I have 3 tabs contain different contents. They loads content from Internet. I use 3 AsyncTasks to do it.
At the beginning, 3 tabs show 3 ProgressBar. I want that everytime one task finishs, it updates the TabSpec and hide the ProgressBar.
The problem is I don’t know how to update the tab spec.
This is my snippet to create TabHost at the beginnig.
final List<View> containerList = new ArrayList<View>();
for(int i = 0; i < 4; ++i) {
final LinearLayout layout = new LinearLayout(this);
final ProgressBar progressBar = new ProgressBar(this);
progressBar.setVisibility(View.VISIBLE);
layout.addView(progressBar);
}
// Prepare labels and icons.
final List<String> tabLabels = Arrays.asList(getResources().getStringArray(R.array.destination_tab_labels));
// TODO Prepare icons here later.
// Populate tabs' contents.
final TabHost tabHost = getTabHost();
for(final String label : tabLabels) {
final TabSpec tab = tabHost.newTabSpec(label);
tab.setContent(new TabContentFactory() {
@Override
public View createTabContent(final String tag) {
// Return ListView here later.
return containerList.get(i++);
}
});
//TODO Add icon here later.
tab.setIndicator(label);
tabHost.addTab(tab);
}
create 3 activities each with its own content, AsyncTask and progressbar. For any activity as the task finishes it will update its content and hide the progressbar.
Add these 3 activites to the tab host like ::