请在这里查看我的博客,您将在其中找到有关如何实现此目标的示例。
一种解决方案是将代表每个计数器的TextView及其在列表中的位置作为键放入HashMap中。
在getView()中
TextView counter = (TextView) v.findViewById(R.id.myTextViewTwo);if (counter != null) { counter.setText(myData.getCountAsString()); // add the TextView for the counter to the HashMap. mCounterList.put(position, counter);}然后,您可以使用处理程序以及在其中发布可运行程序的位置来更新计数器。
private final Runnable mRunnable = new Runnable() { public void run() { MyData myData; TextView textView; // if counters are active if (mCountersActive) { if (mCounterList != null && mDataList != null) { for (int i=0; i < mDataList.size(); i++) { myData = mDataList.get(i); textView = mCounterList.get(i); if (textView != null) { if (myData.getCount() >= 0) { textView.setText(myData.getCountAsString()); myData.reduceCount(); } } } } // update every second mHandler.postDelayed(this, 1000); } }};


