如果我在与我的 ListView 关联的自定义适配器上调用 notifyDataSetChanged()
,所有 View 都应该自行刷新(将调用 getView()
)。
现在我有一个正在监听事件的 BroadcastReceiver。当事件触发时,必须刷新 ListView。我怎样才能做到这一点?
谢谢!
最佳答案
如果您从接收器刷新 ListView ,您将拥有如下代码:
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);
然后你用代码调用它:
Intent intent = new Intent(BROADCAST_ACTION);
sendBroadcast(intent);
如果您需要将刷新作为另一个操作,您只需添加(操作后):
Intent intent = new Intent(BROADCAST_ACTION);
sendBroadcast(intent);
关于android - 如何从 BroadcastReceiver 刷新 ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163075/