本文介绍了Android中标签布局中的进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理标签"布局和进度对话框.当用户进入选项卡布局并更改选项卡时,我想显示进度对话框五秒钟.
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"
推荐答案
尝试一下
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);
TabLayoutActivity .this.runOnUiThread(new Runnable() {
@Override
public void run() {
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);
progressDialog.dismiss();
}
});
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
}
}.start();
}
}
这篇关于Android中标签布局中的进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!