开发者

How can I reload an Activity that exists within a TabView?

I have a Tabview with 3 tabs (each having their own activity). I have a tab that parses 开发者_如何转开发a RSS feed. How can I refresh this feed via a menu button? I tried doing the following but I lose the tabs above of course. Thanks!

  Intent UpdateFeedIntent = new Intent(classA.this, classA.class);

startActivity(UpdateFeedIntent); finish();


See these closely related questions for different approaches:

  • Restarting an activity in a single tab in a TabActivity?
  • Communication between TabActivity and the embedded activity
  • Android TabHost: update tabs from tab’s activity


So thanks Justin for the links. After trying many different ways here is what I finally got to work. (Going to shorten it as much as possilbe, but going to write in the actual code in hopes of less confusion.)

ListAdapter adapter;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(SavedInstanceState);
    rssparser();
    adapter = new MyCustomAdapter(this, R.layout.list_item, rsstitles);
    setListAdapter(adapter);
}

public void onResume() {
    super.onResume();

    rsstitles.clear();  // this line is what finally got the notifyDataSetChanged() to work

    rssparser();
    ((MyCustomAdapter) adapter).notifyDataSetChanged();
    setListAdapter(getListAdapter());
}

If some of that looks funny just comment. There might be some stuff here that is unnecessary, not sure yet about to start testing some other things out to see. Thanks for the links Justin!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜