2016-06-22 6 views
1

처음에는 가운데 버튼이 다른 AlertDialog을 열어주는 세 개의 버튼이있는 AlertDialog을 만듭니다. 버튼을 누른 후 두 번째 AlertDialog이 닫히면 첫 번째 버튼이 닫히는 문제가 있습니다. 두 번째 버튼을 누르면 AlertDialogs 닫힌 것 같아요. AlertDialog. 첫 번째 AlertDialog가 자신의 단추가 다른 AlertDialog을 열 수 있도록자바 안드로이드 - 두 개의 대화 상자, 첫 번째 대화 상자가 두 번째 종료 후 닫히는 것을 방지합니다.

는 내가 원하는이며, 두 번째 AlertDialog이 버튼을 누를 때, 그것은 단지 그 자체를 닫고 다시 처음으로 돌아갑니다. 이것을 달성 할 수있는 방법이 있습니까? 여기

AlertDialog 여는 데 사용되는 버튼의 코드 : 중앙 버튼을 사용하여 다른 AlertDialog를 여는 다른 버튼을 포함하는 AlertDialog을 여는 버튼의 코드 여기

final ImageButton fabgroup = (ImageButton) findViewById(R.id.groupButton); 

있어 (만들기 버튼) 두 번째 단추가 눌려지면 두 단추 모두 닫힙니다 (예 또는 아니오 단추, 두 번째 단추를 닫고 첫 번째 AlertDialog으로 돌아가고 자 할 때 원하는 항목이 아님). 이론적으로는 꽤 혼란스러워서 필요한 경우 명확히하려고 노력할 수 있습니다) :

fabgroup.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(CreateNote.this); 
      helpBuilder.setTitle("Select a group"); 
      helpBuilder.setMessage("Add to group?"); 

      final TextView input = new TextView(mainactiv.this); 
      input.setSingleLine(); 
      input.setText(""); 
      helpBuilder.setView(input); 

      helpBuilder.setNegativeButton("Yes", 
        new DialogInterface.OnClickListener() { 

         public void onClick(DialogInterface dialog, int which) { 
          // Do nothing but close the dialog 
          Toast.makeText(CreateNote.this, "Page has been added to group", Toast.LENGTH_SHORT).show(); 
         } 
        }); 


      helpBuilder.setNeutralButton("Create", new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, int which) { 


        //open another alertbox 
        AlertDialog.Builder helpBuilder2 = new AlertDialog.Builder(CreateNote.this); 
        helpBuilder2.setTitle("Assign a new group"); 
        helpBuilder2.setMessage("Create group?"); 

        final EditText input = new EditText(CreateNote.this); 
        input.setSingleLine(); 
        input.setText(""); 
        helpBuilder2.setView(input); 

        helpBuilder2.setNegativeButton("Yes", 
          new DialogInterface.OnClickListener() { 

           public void onClick(DialogInterface dialog, int which) { 
            // Create Group 
            Toast.makeText(CreateNote.this, "Group has been created", Toast.LENGTH_SHORT).show(); 
           } 
          }); 

        helpBuilder2.setPositiveButton("No", new DialogInterface.OnClickListener() { 

         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          // Do nothing 
         } 
        }); 

        // Remember, create doesn't show the dialog 
        AlertDialog helpDialog2 = helpBuilder2.create(); 
        helpDialog2.show(); 

       } 
      }); 

      helpBuilder.setPositiveButton("No", new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        // Do nothing 
       } 
      }); 

      // Remember, create doesn't show the dialog 
      AlertDialog helpDialog = helpBuilder.create(); 
      helpDialog.show(); 
     } 
    }); 

도움을 주시면 대단히 감사하겠습니다.

답변

0

나는 결국 각 대화 상자를 생성하는 두 개의 별도의 함수를 만들어이 문제를 해결하기 위해 관리, 한 닫을 때 좀처럼, 다른 하나를 만들 수있는 함수를 호출 재활용 (또는 아마도 루핑 기능에 더 가깝습니다). 성능 무거움이 얼마나 큰지는 잘 모르겠지만, 테스트하고있는 것만 큼 문제가없는 것 같습니다. 누군가 이것이 어떻게 문제가 될 수 있는지에 대해 이야기하고 싶다면, 다른 사람들이 경고 대화 상자를 이런 식으로 사용한다는 부정적인 점에 대해 듣고 싶습니다.

0

활동을 대화 상자로 표시 할 수 있습니다. 이것을 매니페스트 파일에 넣으십시오. 이 답변에서

<activity android:theme="@android:style/Theme.Dialog" android:excludeFromRecents="true"/> 

는 : Android Activity as a dialog

+0

불행히도 대화 상자가 닫히지 않는다고 생각됩니다. –