当我开始一个新的活动时,我的progressDialog不会立即出现。我使用AsyncTask相同。我将在下一个活动中从Web服务加载数据。以下是我的异步类:
private class TheTask extends AsyncTask<Void, Void, Void>{
Context con;
Intent aboutusIntent;
TabGroupActivity parentActivity;
private TheTask(Context context)
{
this.con=context;
}
@Override
protected void onPreExecute() {
progDialog = ProgressDialog.show(con, "Loading... ",
"please wait....", true);
}
@Override
protected Void doInBackground(Void... params) {
aboutusIntent = new Intent(con, Departments.class);
parentActivity = (TabGroupActivity)getParent();
//progDialog.show();
return null;
}
@Override
protected void onPostExecute(Void result) {
parentActivity.startChildActivity("Departments", aboutusIntent);
if(progDialog.isShowing())
{
progDialog.dismiss();
}
}
}
我正在创建此类onClick of按钮的实例:
ourdepbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new TheTask(AboutUs.this.getParent()).execute();
}
});
有什么建议么?
最佳答案
Handler mHandler = new Handler();// This statement is to be called by the main thread
ProgressDialog.show();// This statement is to be called by the main thread
Thread t = new Thread(
new Runnable(){
public void run()
{
callWebServicesHereAndFetchingMethod(); //
mHandler.post(new Runnable(){
public void run()
{
ProgressDialog.dismiss();
}
});
}});
t.start();
关于android - 进度对话框不会立即出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4790109/