栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android:ListView中有多个同时倒数计时器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android:ListView中有多个同时倒数计时器

请在这里查看我的博客,您将在其中找到有关如何实现此目标的示例。

一种解决方案是将代表每个计数器的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);        }    }};


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515333.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号