I have a TV Guide activity which extends TabActivity. The tabs are labelled (example)…
Today|Wed|Thu|Fri|Sat|Sun|Mon
The TabHost.TabSpec content of each is set to another activity (GuideListActivity) which extends ListActivity like so…
private void AddGuideTab(String tag, String indicator, String startDate, String endDate) {
Intent intent = new Intent().setClass(this, GuideListActivity.class);
// Set other Intent stuff
TabHost.TabSpec spec = tabHost.newTabSpec(tag).setIndicator(indicator).setContent(intent);
tabHost.addTab(spec);
}
This gives me a 7 day list of all the TV shows for one channel. All good so far.
The problem is how to cleanly recreate all of this when the user wants to view another channel’s listings….
I have a button which the user can press which creates a popup ‘channel selector’ dialog. The dialog correctly returns the new channel name/number but I can’t figure out how to either remove each TabSpec/GuideListActivity in order to start again nor tell the existing GuideListActivity that it needs to repopulate its ListView.
What am I missing? I seem to be going round in circles reading the docs.
My main problem was in how to notify each GuideListActivity that the channel had been changed.
I solved this by creating a nested class in the GuideListActivity which extends BroadcastReceiver and the TabActivity now uses
sendStickyBroadcast();to send a sticky Intent containing the current channel selection. Each time a GuideListAvtivity is resumed, it can check the sticky Intent and adjust its ListView if the channel selection has changed.