gpt4 book ai didi

Android ProgressDialog 不显示

转载 作者:搜寻专家 更新时间:2023-11-01 08:04:35 24 4
gpt4 key购买 nike

这是我的代码中连接到对话框的部分。他们按下按钮后,它应该出现,出现后,它应该处理数据,完成后,它应该隐藏起来。但它甚至没有出现?

ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Prosimo počakajte da naloži podatke.");
dialog.setIndeterminate(false);
dialog.setCancelable(false);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

private Button.OnClickListener listener = new Button.OnClickListener() {
public void onClick(View v){
if(selectedClass >= 0){
dialog.show();

... data processing ...

Intent firstUpdate = new Intent(context, ConfigurationActivity.class);
firstUpdate.setAction("android.appwidget.action.APPWIDGET_ENABLED");
firstUpdate.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widget_id);
context.sendBroadcast(firstUpdate);

dialog.dismiss();
setResult(RESULT_OK, firstUpdate);
finish();
} else {
Log.i("Schedule", "Missing selections");
}
}
};

感谢您的帮助。

最佳答案

多亏了“Pragnani”,我才得以成功。这是最终代码:

private class ProgressTask extends AsyncTask<String, Void, Boolean> 
{
private ProgressDialog dialog;
private ConfigurationActivity activity;

public ProgressTask(ConfigurationActivity activity)
{
this.activity = activity;
context = activity;
dialog = new ProgressDialog(context);
}

private Context context;

protected void onPreExecute()
{
dialog = new ProgressDialog(context);
dialog.setMessage("Prosimo počakajte da naloži podatke.");
dialog.setIndeterminate(false);
dialog.setCancelable(false);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.show();
}

@Override
protected void onPostExecute(final Boolean success)
{
if (dialog.isShowing())
{
dialog.dismiss();
}
if (success)
{
Toast.makeText(context, "OK", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context, "ERROR", Toast.LENGTH_LONG).show();
}
}

@Override
protected Boolean doInBackground(final String... args)
{
try {
... processing ...

return true;
} catch (Exception e){
Log.e("Schedule", "UpdateSchedule failed", e);
return false;
}
}

}

调用类:

new ProgressTask(ConfigurationActivity.this).execute();

谢谢 Pragnani!

关于Android ProgressDialog 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16152019/

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