Android的onResume更新列表适配器 [英] Android onResume update list adapter

查看:219
本文介绍了Android的onResume更新列表适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个列表适配器来显示不同​​的商店,当有人选择一个存储需要他们到一个新的活动,在那里他们可以添加商店收藏的屏幕上。

I'm using a list adapter to show different stores, when someone selects a store it takes them to a new activity where they can add the store to favorite on that screen.

有一个后退按钮调用结束(); 可以追溯到与ListView屏幕。

There is a Back button on that calls finish(); that goes back to the screen with the listview.

现在的问题是,不更新的列表视图(即不显示,这家店被添加到最爱的话)。我想这code,但没有运气:

Now the problem is the listview isn't updated (ie. doesn't show that the store is added to favorite already). I tried this code but no luck:

@Override
public void onResume() {
    super.onResume();
    list.setAdapter(null);      
    updateMyList();
    adapter=new LazyAdapter(this, ((String[])names.toArray(new String[0])), 
        ((String[])status.toArray(new String[0])));
    list.setAdapter(adapter);
}

updateMyList()调用服务器API和更新的名称和状态数组。

updateMyList() calls the server API and updates the names and status arrays.

通过这个$ C C列表$并没有真正更新...

With this code the list doesn't really update...

推荐答案

您应该setAdapter在你的的onCreate()只,在 onResume() 你刚刚打电话 adapter.notifyDataSetChanged()数据的新的集合。这将刷新您的ListView数据的新的集合。

You should setAdapter in your onCreate() only, inside onResume() you just had to call adapter.notifyDataSetChanged() with the new collection of data. This will refresh your ListView with the new collection of data.

这篇关于Android的onResume更新列表适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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