gpt4 book ai didi

android - 如何在 AsyncTask 的 DialogFragment 中显示 ProgressDialog

转载 作者:行者123 更新时间:2023-11-29 14:37:48 25 4
gpt4 key购买 nike

我的 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();
}

注意:

经过更多调试后,我发现我的 ProgressDialog 显示在 DialogFragment 下方,但我希望它显示在 DialogFragment 之上。

SO 帖子 How can I open a ProgressDialog on top of a DialogFragment?提及,

Apparently thats a widely complained about subject with ProgressDialog, I suggest you try a normal dialog, created with the builder and whose layout (a custom one made by you) includes the progress bar or loading or whatever you need. This should solve your problem.

但我想知道您的应用程序是否在不同的 View 中始终使用 ProgressDialog 那么它是使用自定义生成器执行此操作的最佳方式吗?

它阻碍了应用程序的一致性。而且,那是另一种方式。

最佳答案

@我的天

你只差两步。

  1. onCreateDialog() as

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    return dialog;
    }
  2. onStart() 作为

    @Override
    public void onStart() {
    super.onStart();
    new BackgroundDataLoad().execute();
    }

现在您的加载任务将在对话框创建后执行,因此现在您可以查看正在显示的进度对话框。

关于android - 如何在 AsyncTask 的 DialogFragment 中显示 ProgressDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25264716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com