【发布时间】:2016-01-22 06:28:47
【问题描述】:
我有一个使用 ViewPager 浏览三个片段的选项卡式活动。 当我加载一个片段时,我必须加载一些数据,所以我将加载代码放在 AsyncTask 中,我想在加载数据时显示一个 ProgressDialog。 这是我的 AsyncTask 中的代码:
public GetGeneralitaTask(Context c){
this.c=c;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=new ProgressDialog(c);
progressDialog.setMessage("Caricamento...");
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.show();
}@Override
protected String doInBackground(Void... params) {
the loading part....
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
Log.e("ending ", "second task");
}
然后在我调用的 Fragment onCreateView 中:
getGeneralitaTask=new GetGeneralitaTask(getActivity());
getGeneralitaTask.execute();
try {
getGeneralitaTask.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
但什么都没有显示...视图只是静止不动,直到数据加载并填充视图
【问题讨论】:
标签: android