2010-12-11 2 views
1

나는 데이터베이스에 되돌릴 수없는 일을하기 전에 사용자에게 확인을 두 번 요청하려고합니다. 문제는 외부 클릭 핸들러가 내부 클릭 핸들러를 기다리지 않는다는 것입니다. 첫 번째 대화 상자에서 예 버튼을 클릭하면 두 번째 대화 상자가 잠시 표시되지만 바깥 쪽 핸들러가 실행되고 완료 되더라도 궁극적으로 두 대화 상자 모두가 손상됩니다.Android 중첩 AlertDialog - 이것이 가능합니까?

new AlertDialog.Builder(ActivityMain.this).setMessage(
    "Are you sure?").setPositiveButton("Yes", 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface arg0, int arg1) { 

    new AlertDialog.Builder(ActivityMain.this).setMessage(
     "Are you really sure?").setPositiveButton("Yes", 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface arg0, int arg1) { 

    .... 

왜 그렇습니까?

답변

2

그냥 디자인 새 XML 당신의 대화 등의 레이아웃과 새로운 작업을 생성하고이 @android하는 테마의 설정 : 스타일/Theme.Dialog를 활동 태그 전에서 매니페스트 파일에서 다음의

<activity android:theme="@android:style/Theme.Dialog" android:name="LocationDialog"> </activity> 

대화를 클릭하여 청취자 코드를 활성화하십시오.

new AlertDialog.Builder(ActivityMain.this).setMessage(
    "Are you sure?").setPositiveButton("Yes", 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface arg0, int arg1) { 
      Intent i = new Intent(YourActivity.this, NewActivity.class); 
      startActivity(i); 
     } 

이렇게하면 새로운 활동이 대화 상자로 시작되어 작업을 쉽게 적용 할 수 있습니다.

+0

아직 시도하지는 않았지만 마음에 들었습니다. – cdonner

2

대화 상자가 차단되지 않기 때문입니다. 표시되는 즉시 처리는 다음 코드 행으로 이동합니다. 그래도 사용자 상호 작용을 기다리는 대화 상자가 표시됩니다.