如何刷新从一个BroadcastReceiver一个ListView? [英] How to refresh a ListView from a BroadcastReceiver?

查看:344
本文介绍了如何刷新从一个BroadcastReceiver一个ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我称之为 notifyDataSetChanged()关联到我的ListView自定义适配器上,所有的意见应刷新自理( getView()将被调用)。
现在我有一个监听事件一个BroadcastReceiver。当事件触发时,ListView控件必须刷新。我怎样才能做到这一点?
谢谢!

If I call notifyDataSetChanged() on the custom adapter associated to my ListView, all the views should refresh themself (getView() will be called). Now I have a BroadcastReceiver that is listening to an event. When the event fires, the ListView must be refreshed. How can I achieve this? Thanks!

推荐答案

如果您在接收器刷新列表视图你有code是这样的:

If you refresh listview from receiver you'll have code like this:

BroadcastReceiver br;
public final static String BROADCAST_ACTION = "BROADCAST_ACTION";
br = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
//code refreshing...
}
};
IntentFilter intFilt = new IntentFilter(BROADCAST_ACTION);
registerReceiver(br, intFilt);

和你code调用它:

Intent intent = new Intent(BROADCAST_ACTION);
sendBroadcast(intent);

如果您需要的刷新是你只需要添加(动作后)另一个动作:

If you need the refresh to be another action you just need to add (after action):

Intent intent = new Intent(BROADCAST_ACTION);
sendBroadcast(intent);

这篇关于如何刷新从一个BroadcastReceiver一个ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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