私の ProgressDialog は、 oncreate メソッドで show() を使用する場合に機能します。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pd = ProgressDialog.show(this, "Working", "Retreiving Neaby Restaurants", true, true); // initializes the progress dialog
pd.setCanceledOnTouchOutside(false); // on newer versions of android touching outside of the screen will close the dialog. I decided to make it only cancelable when the back button is pressed.
setContentView(R.layout.nearby_places_list);
ただし、on create() ではないため、非同期タスクで使用するとダイアログ コードが機能しません。引数 show(this, "Working", "Retreiving Neaby Restaurants", true, true) は、onCreate() の外では許可されていません。
class MyAsync extends AsyncTask<Void, Integer, Boolean>{ // this task is for populating the listview
@Override
protected void onPreExecute() {
//ProgressDialog.show(context, "Working", "Retreiving Neaby Restaurants");
pd = ProgressDialog.show(this, "Working", "Retreiving Neaby Restaurants", true, true); // initializes the progress dialog
pd.setCanceledOnTouchOutside(false); // on newer versions of android touching outside of the screen will close the dialog. I decided to make it only cancelable when the back button is pressed.
}
非同期タスクの開始時にダイアログを表示したかったのですが、そのタスクが呼び出される少し前に、これはやや動揺しています。
したがって、私の質問は、ユーザーが実際に非同期タスクの使用を開始するまで、onPreExecute() の非同期タスク内でこれを機能させる方法です。