私の目標は、ユーザーがアプリに戻ったときにモーダル ダイアログを表示することです。このモーダル ダイアログは、ユーザーが定義した 6 桁の PIN を要求します。私は Java GUI と Android の開発が初めてなので、私の問題は.....
Enterpin ダイアログが表示されているときにユーザーがアプリを最小化することを選択した場合、ユーザーがアプリに戻ると、ダイアログが互いに重なり合っていることがわかりました。PIN の入力中に最小化してアプリに戻った回数だけ PIN を入力させる。
/**
* On restart called when the app is being restarted on the screen
*/
@Override
public void onRestart() {
super.onRestart();
// must prompt with modal dialog for pin
final Dialog dialog = new Dialog(this);
dialog.setCancelable(false);
// check pin
dialog.setCanceledOnTouchOutside(false);
// set view to enterpin XML screen
dialog.setContentView(R.layout.enterpin);
// show dialog
if (!dialog.isShowing()) {
dialog.show();
}
// listen for button being clicked
Button button = (Button) dialog.findViewById(R.id.pinlogin);
button.setOnClickListener(new OnClickListener() {// anonymous inner
// class
// implementation
@Override
public void onClick(View v) {
EditText editText = (EditText) dialog
.findViewById(R.id.enterpintext);
try {
int enteredPin = Integer.parseInt(editText.getText()
.toString());
SharedPreferences sharedP = Prefs.get(WebViewActivity.this);
int temp = sharedP.getInt("pin", 0);
if (enteredPin == temp) {
pinCheck = true;
dialog.dismiss();
} else {
pinCheck = false;
dialog.setTitle("Incorrect Pin");
}
} catch (NumberFormatException e) {
Dialog dialog2 = new Dialog(WebViewActivity.this);
dialog2.setTitle("Enter Numbers Only");
dialog2.setCanceledOnTouchOutside(true);
dialog2.show();
}
}
});
}
ダイアログの初期化を、プログラミングが悪いと感じることなく移動できる場所はありますか? 私のDialogインスタンスはメソッドの存続期間中しか存在しないため、私が試したdialog.isShowing()メソッドが機能しない理由を理解しています。
また、携帯電話を縦向きから横向きに 90 度回転させたり、その逆にしたりすると、ダイアログが消えてしまうことにも気付きました。ダイアログを再描画できるように、この強制再描画が発生したときに呼び出される一連のメソッドを誰かが指摘できますか?