このテーマにはいくつかのバリエーションがあるようです。このアイテムを保存AlertBoxしたいのですか?彼らがOKと応答した場合、私Alertboxは離れてProgressDialogボックスに置き換えてもらいたいのですが、アイテムの保存が完了すると、それは却下されます。
以下の現在のコードは、OK /キャンセルAlertBoxと却下を正しく示し、トーストを正しく示しています。しかし、ユーザーが[OK]を選択するProgressDialogと、すべてが完了した後にショーが消えることはありません。OK /キャンセルボタンは、アイテムが保存されるまで押されたままになります。ユーザーが[OK]を押した場合は、AlertBoxを表示してから表示し、ProgressDialog保存が完了したら閉じます。
{
Vibrate(ClickVibrate);
final ProgressDialog Dialog = ProgressDialog.show(v.getRootView().getContext(), "Loading", "Please wait...", true);
if(AlertDialogProcessing==0)
{
ProgressDialog progress;
final String title="Save Item";
final String message="Press OK to save or CANCEL.";
final String ok="OK";
final String cancel="CANCEL";
final AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setCancelable(true);
alertbox.setIcon(android.R.drawable.ic_dialog_alert);
alertbox.setTitle(title);
alertbox.setMessage(message);
alertbox.setNegativeButton(cancel, null);
final AlertDialog dlg = alertbox.create();
alertbox.setPositiveButton(ok,new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1)
{
dlg.dismiss();
Dialog.show();
Vibrate(ClickVibrate);
Drawable drawable= getItem(imageSelect);
AlertDialogProcessing=1;
//task that takes 3 seconds
AlertDialogProcessing=0;
Toast.makeText(getApplicationContext(), "Item Saved.", Toast.LENGTH_LONG).show();
}
});
alertbox.setNegativeButton(cancel,new DialogInterface.OnClickListener(){ public void onClick(DialogInterface arg0, int arg1){AlertDialogProcessing=0; Vibrate(ClickVibrate); } });
alertbox.show();
}
Dialog.dismiss();
}