从CountDownTimer更新为一个TextView的多个实例文本 [英] Updating text for multiple instances of a TextView from a CountDownTimer

查看:459
本文介绍了从CountDownTimer更新为一个TextView的多个实例文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更新一个TextView的文本时,有一个问题。

I am having an issue when attempting to update a TextView's text.

我在我所创建的布局,一个空的ListView一个MainActivity。
为了填补这一ListView的自定义ListItems的我已经创建了一个检索信息填写到ListItems的,​​也填充加载到ListItems的数据自定义BaseAdapter的自定义AsyncTaskLoader。

I have a MainActivity in which i have created a layout with an empty ListView. To fill this ListView with custom ListItems i have created a custom AsyncTaskLoader that retrieves information to fill onto the ListItems and also a custom BaseAdapter that fills the data loaded into the ListItems.

这部分没有任何错误,它只是完美。

This part has no errors and it does it just perfectly.

不过,试图从在ListView一个列表项更新一个TextView的文本时,我有一个问题。
你看,我创建了一个自定义的CountDownTimer这需要所谓OnTickListener作为构造函数的参数的接口。
我每次都一个独特的ID我创建了一个列表项,我用它来存储在一个HashMap的列表项的TextView的,也存储在一个HashMap的CountDownTimer。这些包含HashMap被创建和保存自定义BaseAdapter里面。

However, i am having an issue when attempting to update the text on a TextView from a ListItem in the ListView. You see, i have created a custom CountDownTimer which takes an interface called OnTickListener as parameter in the constructor. I have a unique id for each time i created a ListItem and i am using this to store the TextView for that ListItem in a HashMap and also to store the CountDownTimer in a HashMap. These HashMaps are created and kept inside the custom BaseAdapter.

该BaseAdapter还实现OnTickListener。

The BaseAdapter also implements OnTickListener.

每次MyCountDownTimer电话OnTick它调用构造函数中提供给它的OnTickListener,并传递两个参数:INT ID和字符串文字

Every time a MyCountDownTimer calls OnTick it calls the OnTickListener provided to it in the constructor and passes two parameters: int id and String text.

这将调用OnTickListener的唯一方法BaseAdapters implementaton:公共无效OnTick(INT ID,字符串文本)

This will call the BaseAdapters implementaton of OnTickListener's only method: public void OnTick(int id, String text).

在onTick方法我做到以下几点:

In the onTick method i do the following:


  1. 找到在我前面提到的HashMap中的ID TextView的。

  2. 更新TextViews文本。

现在这似乎在某种程度上工作。因为如果我向上和向下滚动我可以看到,一旦它被显示在屏幕上再上TextViews文本将被更新。但是,如果它已经显示在屏幕上它不更新的TextView。
我曾试着拨打TextView.invalidate()和TextView.postInvalidate()。在我绝望我甚至试图建立一个处理程序,将发布一个Runnable这将尝试更新的TextView。

Now this seems to work in some way. Because if i scroll up and down i can see that the text on the TextViews will be updated once it is shown on the screen again. But it does not update the TextView if it is already shown on the screen. I have tried to call TextView.invalidate() and TextView.postInvalidate(). In my desperation i even tried creating a Handler that would post a Runnable which would try to update the TextView.

但似乎没有奏效。有什么想法,我怎么可能能够更新TextView的?

But nothing seems to be working. Got any ideas as to how i may be able to update the TextView?

TL DR:
我需要知道我怎么可以更新列表项内一个TextView - 这是一个活动的一部分 - 从一个BaseAdapter创建CountDownTimer

TL DR: I need to know how i can update a TextView inside a ListItem - that is part of an Activity - from a CountDownTimer created in a BaseAdapter.

抱歉文本墙^^

推荐答案

您应该更新data'of适配器,数据应包含将在每个TextView中显示的每个项目的内容。

You should update the 'data'of the adapter,that data should contain the content of each item that will be displayed on each textview.

然后调用notifydatasetchanged()在ADA $ P $公关。

Then call notifydatasetchanged() on the adaprer.

这篇关于从CountDownTimer更新为一个TextView的多个实例文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆