Androidアラートダイアログ - 押された後にOKボタンを非表示にする方法
-
28-09-2019 - |
質問
Androidアプリを開発しています。
ダイアログウィンドウは、計算が行われている間に数秒間前景にとどまるため、ユーザーが押した後にOKボタンを非表示にしたいと思います。
これはコードです:
new AlertDialog.Builder(this)
.setMessage("This may take a while")
.setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// hide the OK button - how?
// a lot of computation
}
})
.show();
どうすればそれを達成できますか?
PS:計算を処理するためのより高度な手法に興味がありません(進行状況ダイアログ、マルチスレッドなど)。
ありがとう。
解決
.setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((AlertDialog)dialog).getButton(which).setVisibility(View.INVISIBLE);
// the rest of your stuff
}
})
他のヒント
setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
どこ dialog
は DialogInterface
.
ボタンの可視性を目に見えないように設定できます。
ok.setVisibility(View.INVISIBLE);
所属していません StackOverflow