Android 进度对话框显示这么晚?
问题
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
progressDialog = ProgressDialog.show(ContactMainActivity.this, "",
"Loading. Please wait...",true);
setContentView(R.layout.contactlist);
contactListView=getListView();
contactListView.setTextFilterEnabled(true);
contactListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Thread t = new Thread() {
public void run() {
try{
runOnUiThread(new Runnable() {
public void run() {
//stuff that updates ui
queryAllRawContacts();
progressDialog.dismiss();
}
});
registerForContextMenu(contactListView);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
// dismiss the progress dialog
}
};
t.start();
}
这是我的活动类的 onCreate 方法的
。此活动实际上是选项卡小部件的一个选项卡。因此,当我单击此选项卡并运行该活动时,它会等待大约 2 秒,然后显示类似 10 毫秒的进度对话框,并使用数据更新 UI。并关闭进度对话框。我想要实现的是,一旦单击该选项卡,就会显示进度对话框,并且加载数据大约需要 2-3 秒。加载并更新 UI 后,进度条将消失。
谢谢
Here is the problem
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
progressDialog = ProgressDialog.show(ContactMainActivity.this, "",
"Loading. Please wait...",true);
setContentView(R.layout.contactlist);
contactListView=getListView();
contactListView.setTextFilterEnabled(true);
contactListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Thread t = new Thread() {
public void run() {
try{
runOnUiThread(new Runnable() {
public void run() {
//stuff that updates ui
queryAllRawContacts();
progressDialog.dismiss();
}
});
registerForContextMenu(contactListView);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
// dismiss the progress dialog
}
};
t.start();
}
this is onCreate method of my activity class.
This activity actually one tab of a tabwidget. So when I click this tab and run the activity, it waits about 2 seconds and then show progress dialog like 10 millisec and updates the UI with the data. and dismiss progress dialog. What I would like to achieve is that as soon as the tab is clicked, the progress dialog will be shown and it takes about 2-3 seconds to load data. after loading and updating the UI the progress bar will be dismissed.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
queryAllRawContacts()
不需要在 UI 线程上运行。将您的代码更改为以下内容:queryAllRawContacts()
needs to not be run on the UI thread. Change your code to the following: