My *_*God 1 android progressdialog android-dialogfragment
我ProgressDialog没有显示 - 它在AsyncTask类BackgroundDataLoad中定义.
DialoguePopup类 -
public class DialoguePopup extends DialogFragment {
public DialoguePopup newInstace()
{
DialoguePopup dialogFragment = new DialoguePopup();
return dialogFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
//view related code..
//Calculation logic data load in background
new BackgroundDataLoad().execute();
return view;
}
class BackgroundDataLoad extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Calculating ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params)
{
//Data that can take 8 seconds to load is in background process
return null;
}
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
pDialog.dismiss();
}
Run Code Online (Sandbox Code Playgroud)
注意:
经过一些调试之后,我才知道我的ProgressDialog显示在DialogFragment下面,但我希望它在DialogFragment之上.
SO帖子如何在DialogFragment上打开ProgressDialog?提及,
显然,这是一个广泛抱怨使用ProgressDialog的主题,我建议您尝试使用构建器创建的普通对话框,其布局(由您制作的自定义)包括进度条或加载或您需要的任何内容.这应该可以解决您的问题.
但是我想知道你的应用程序是否ProgressDialog在不同的视图中使用,那么使用自定义Builder是最好的方法吗?
它会阻碍应用程序的一致性.而且,这是另一种方式.
@ 天哪
你只需两步之遥.
onCreateDialog() 如
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
Run Code Online (Sandbox Code Playgroud)onStart() 如
@Override
public void onStart() {
super.onStart();
new BackgroundDataLoad().execute();
}
Run Code Online (Sandbox Code Playgroud)现在你加载任务将在对话框创建后执行,所以现在你可以查看正在显示的进度对话框.
| 归档时间: |
|
| 查看次数: |
4479 次 |
| 最近记录: |