views:

138

answers:

2

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();

A: 

See these closely related questions for different approaches:

Justin
Thanks I searched around but guess I wasn't using the right words ;(
fwaokda
A: 

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!

fwaokda
I see, so you wanted the activity to refresh its contents when it returned to view. The links were more to do with the hierarchy of tabbed apps and techniques for inter-activity communication. Glad that `notifyDataSetChanged()` solved your problem. Going forward, remember to call it from the UI thread or you may crash.
Justin