I use asynctask
quite often however this time it doesn't work!
I have a UI contains a viewpager
and fragments
. To populate the view, it takes about 3 secs. Now I want to show the ProgressDialog until it finishes by using AsyncTask
. But the ProgressDialog
is not showing!!!!
Anybody can tell me the solution? Thanks
onCreate(...){
setContentView(...)
new LoadUI(MyActivity.this).execute();
}
public class LoadUI extends AsyncTask<Void, Void, Void>{
ProgressDialog pd;
Context context;
public LoadUI(Context mContext) {
this.context = mContext;
pd = new ProgressDialog(mContext);
aViewPager = (ViewPager) findViewById(R.id.aPagerDay);
}
@Override
protected void onPreExecute() {
pd.show();
}
@Override
protected Void doInBackground(Void... params) {
//Create ViewPager
//Create pagerAdapter
return null;
}
@Override
protected void onPostExecute(Void result) {
if (pd.isShowing()) {
pd.dismiss();
}
super.onPostExecute(result);
}
}