开发者

Update a ListView located in a different tab

I'm a newbie Android developer and I'm trying to create an Android application with 2 tabs, using Activities for each tab. This is basically how it should work:

  • Tab A has 1 button
  • Tab B has 1 ListView
  • When the user clicks on the button in Tab A the application must put a value in the ListView in Tab B

My question is: how can I update the ListView in Tab B when I click on the button in Tab A? I know how to put values in a ListView when it's on the same tab where the button is located but my approach doesn't work when the ListView is in a different tab. I tried...

ListView myListInTabB = (ListView)findViewById(R.id.list_on_tabB);
开发者_开发百科

but didn't work :-/

Any suggestion? Thanks in advance.


Im not sure you actually need seperate activites for this, unless you are doing some specific work between your activities. Most tab solutions you see in Android solutions work simply by hiding the Views that are not related to the current shown tab. You will find the "visibility" property helpful for making this happen. Also, making sure all of your Views are in the same Activity lets you access their objects all the time, regardless of their visibility.


You don't do that. Just ensure the underlying Adapter has the latest data. Calling requery() on the Cursor does the trick, it automatically updates the ListView attached to it.

Edit: use notifyDataSetChanged() to let the list know that the data is stale.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜