내 목표는 사용자가 내 앱으로 돌아갈 때 모달 대화 상자를 표시하는 것입니다. 이 모달 대화 상자는 정의 된 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.isShowing() 메서드가 작동하지 않는 이유를 이해합니다.
휴대 전화를 세로 방향에서 가로 방향으로 90도 돌리면 어쨌든 대화 상자가 사라집니다. 누군가가 강제로 다시 그리기를 할 때 호출되는 메서드 체인을 지적하여 대화 상자를 다시 그릴 수 있습니까?
protected android.app.Dialog onCreateDialog(int id) {
if (this.currentDialog != null) {
this.currentDialog.dismiss();
}
this.currentDialog = null;
switch (id) {
case DIALOG_SPINNER:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage(getString(R.string.dialog_Spinner_UpdatingAccount));
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.currentDialog = progressDialog;
break;
}
return this.currentDialog;
}
나는 또한 폐기 :
코드가 내 문제를 해결했습니다 : setCanceledOnTouchOutside가 호출되었습니다. 그러나, 나는 Dialog 대신 Activity를 서브 클래스 화했다. 이 경우 호출은 setFinishOnTouchOutside입니다. 그것은 android : theme = "@ android : style/Theme.Dialog"와 함께 사용하면 대화처럼 행동을합니다. –