从另一个活动的Android刷新列表视图适配器 [英] Android refresh listview adapter from another activity
问题描述
我用Google搜索了很多,但无法找到合适的答案。
I Googled a lot, but can't find the proper answer.
我有两个的活动。每个活动的'有'一列表视图
I've got two activities. Each of that activities 'has' one listview.
每个列表视图这有一个自定义的 ArrayAdapter 。所以:
Each of that listviews have a custom ArrayAdapter. So :
活动1 ---->列表视图1 ------>自定义ArrayAdapter 1
Activity 1 ----> Listview 1 ------> custom ArrayAdapter 1
活动2 ---->列表视图2 ------>自定义ArrayAdapter 2
Activity 2 ----> Listview 2 ------> custom ArrayAdapter 2
当我preSS一个按钮,在活动1 ,然后它刷新在列表视图1 (它的适配器)。
When I press a button in Activity 1, then it refreshes the Listview 1 (it's adapter).
目标是:我必须做列表视图2刷新过那段时间。我怎样才能做到这一点?我读过一些关于广播,但没有充分理解它。
The goal is : I have to do a refresh on Listview 2 too that time. How can I achieve this ? I've read something about broadcasting, but didn't understand it well.
感谢您!
推荐答案
如果您在活动1,它的无用的尝试刷新活性2的列表视图作为其不可见。然而,你可以做的是,当用户切换到活性2,只需调用适配器 notifyDataSetChanged()
在 onResume()事件和你活性2将被刷新。
if you are in Activity1, its useless to try to refresh Activity2's listview as its not visible. However, what you can do is, when the user is switched to Activity2, just call adapter's notifyDataSetChanged()
in its onResume() event and your activity2 will be refreshed.
这篇关于从另一个活动的Android刷新列表视图适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!