I am working on Tab layout and progress dialog. I want to show progress dialog for five sec when user comes on the tab layout and when user changes the tabs.
I used following same code to show the progress dialog in both conditions.
public class TabLayoutActivity extends TabActivity {
ProgressDialog progressDialog;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tablayoutview);
progressDialog = ProgressDialog.show(TabLayoutActivity.this, "",
"Loading. Please wait...");
new Thread() {
public void run() {
try {
Thread.sleep(5000);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec;
Intent intent = new Intent().setClass(
getApplicationContext(), FirstTabActivity.class);
tabSpec = tabHost.newTabSpec("first").setIndicator("First")
.setContent(intent);
tabHost.addTab(tabSpec);
intent = new Intent().setClass(getApplicationContext(),
SecondTabActivity.class);
tabSpec = tabHost.newTabSpec("second")
.setIndicator("Second").setContent(intent);
tabHost.addTab(tabSpec);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
}
}
The progress dialog working fine, but contents of the tabs does not display. It is showing following error.
"Only the original thread that created a view hierarchy can touch its views"