こんばんは。
miccoです。
以下のとおり実装したところ、データ削除処理中にきちんとプログレスダイア
ログが表示されました。ありがとうございました!
Javaの基礎知識が欠落していますので、オーバーライドするメソッドの引数
の型宣言が「void」ではなく「Void」である意味や「Void... params」の「...」
の意味等よく理解できていない部分もありますが、ひとまずおまじないとい
うことで使います^^;
もっとJavaの基礎を学んだ方が良さそうです。
ご協力ありがとうございました。
public void onClick(View view)
{
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setTitle("確認");
ad.setMessage(全データを消去します");
ad.setPositiveButton("キャンセル",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface di,int which_button)
{
//何もしない
}
});
ad.setNegativeButton("消去",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface di,int which_button)
{
BackgroundTask task = new BackgroundTask(A1.this,"データ消去中","しばらくお待ち下さ
い");
task.execute();
}
});
ad.create();
ad.show();
}
public class BackgroundTask extends AsyncTask<Void,Integer,Boolean>
{
private Context context = null;
private ProgressDialog dialog = null;
private String title;
private String msg;
public BackgroundTask(Context context,String title,String msg)
{
this.context = context;
this.title = title;
this.msg = msg;
}
//処理実行前メソッド
protected void onPreExecute()
{
//プログレスダイアログ設定
dialog = new ProgressDialog(context);
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setTitle(title);
dialog.setMessage(msg);
dialog.show();
}
//処理実行中メソッド
protected Boolean doInBackground(Void... params)
{
//データ消去処理
deleteData();
return true;
}
//処理実行後メソッド
protected void onPostExecute(Boolean result)
{
//プログレスダイアログ消去
dialog.dismiss();