2014-02-16 3 views
0

여러 개의 팝업을 표시하는 데 문제가 있습니다. 지금 나는 AlertDialog를 가지고있다. 사용자가 편집하고자하는 파일의 이름을 넣을 EditView가 있는데 File 객체와 Writer에 전달할 것이고 새로운 Dialog는 팝업이된다. 사용자에게 음악 플레이어를 실행할지 묻습니다.순차적 대화 상자 팝업을 표시하는 방법은 무엇입니까?

그러나 지금은 첫 번째 AlertDialog에서 '확인'을 누르면 아무 일도 일어나지 않습니다. 내가 뭘 잘못하고 있는지 모르겠다. 어떤 도움이 필요합니까? 여기 내 코드가있다.

//naming the playlist 
    AlertDialog.Builder alert = new AlertDialog.Builder(this); 

    alert.setTitle("Exporting Playlist"); 
    alert.setMessage("Enter the name of the playlist!"); 

    // Set an EditText view to get user input 
    final EditText input = new EditText(this); 
    alert.setView(input); 

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
      name = input.getText().toString() + ".m3u"; 
      popup = true; 
     } 
    }); 

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
     // Canceled. 
     } 
    }); 

    alert.show(); 


    //after the playlist is named, put songs into file 
    if (popup){ 
     popup = false; 
     final File list = new File(mp3folderPath + name); 
     FileWriter writer; 
     BufferedWriter write; 

     ArrayList<String> playlist = new ArrayList<String>(); 
     Log.d("poo", "mAdapter count: "+mAdapter.getCount()); 
     for (int i=0; i < mAdapter.getCount(); i++) { 
      playlist.add(mAdapter.getItem(i)); 
     } 
     Log.d("poo", playlist.toString()); 

     //write the songs to the m3u playlist 
     writer = new FileWriter(list); 
     write = new BufferedWriter(writer); 
     for (int i = 0; i<playlist.size(); i++){ 
      String[] name = playlist.get(i).split(" : "); 
      Log.d("poo", name[0]); 
      write.append(name[0]+"\n"); 
     } 
     write.close(); 

     //popup window 
     CharSequence choices[] = new CharSequence[] {"Launch Music Player", "Quit"}; 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Exported playlist!"); 
     builder.setItems(choices, new DialogInterface.OnClickListener() { 

      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       if (which == 0) { 
        Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER); 
        startActivity(intent); 
        finish(); 
       } 
       else { 
        finish(); 
       } 
      } 
     }); 
    builder.show(); 
    } 
} 
+0

단지 제안 (팝업) 할 수없는 경우 사용자가 "ok"를 클릭하면 해당 조건으로 작성된 것을 수행 할 함수를 호출합니다. – user2450263

답변

2

순차적 팝업, 연속 팝업 (들)에 대한 조건 코드를 보여주기 위해 온 클릭 처리기에 있어야 .
AlertDialog1는 AlertDialog2을 보여줄 것 코드 ...이 같은

시도 뭔가 포함한다 : 당신이 조건을 작성해야 할 이유

//naming the playlist 
       AlertDialog.Builder alert = new AlertDialog.Builder(this); 

       alert.setTitle("Exporting Playlist"); 
       alert.setMessage("Enter the name of the playlist!"); 

       // Set an EditText view to get user input 
       final EditText input = new EditText(this); 
       alert.setView(input); 

       alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 
        //check if the name is not null 
         name = input.getText().toString() + ".m3u"; 
        //Now instead of popup = true; 
       //call func to name the playlist and next dialog 
         callNextDialog(); 
        } 
       }); 

       alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 
        // Canceled. 
        } 
       }); 

       alert.show(); 


       //after the playlist is named, put songs into file 
     //  if (popup){ 
     //   popup = false; 
     //   } 

        public void callNextDialog(){ 
final File list = new File(mp3folderPath + name); 
        FileWriter writer; 
        BufferedWriter write; 

        ArrayList<String> playlist = new ArrayList<String>(); 
        Log.d("poo", "mAdapter count: "+mAdapter.getCount()); 
        for (int i=0; i < mAdapter.getCount(); i++) { 
         playlist.add(mAdapter.getItem(i)); 
        } 
        Log.d("poo", playlist.toString()); 

        //write the songs to the m3u playlist 
        writer = new FileWriter(list); 
        write = new BufferedWriter(writer); 
        for (int i = 0; i<playlist.size(); i++){ 
         String[] name = playlist.get(i).split(" : "); 
         Log.d("poo", name[0]); 
         write.append(name[0]+"\n"); 
         write.close(); 
         //popup window 
      CharSequence choices[] = new CharSequence[] {"Launch Music Player", "Quit"}; 

         AlertDialog.Builder builder = new AlertDialog.Builder(this); 
         builder.setTitle("Exported playlist!"); 
         builder.setItems(choices, new DialogInterface.OnClickListener() { 

          @Override 
          public void onClick(DialogInterface dialog, int which) { 
           if (which == 0) { 
         Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER); 
            startActivity(intent); 
            finish(); 
           } 
           else { 
            finish(); 
           } 
          } 
         }); 
        builder.show(); 
        } 
       } 
2

AlertDialog.show()는 대화 상자가 사라질 때까지 기다리지 않습니다. 그것은 즉시 반환합니다. 즉, 사용자가 선택을 한 후에해야 할 일의 모든 논리는 대화 상자의 양수 버튼의 onClick 함수에 있어야합니다. 기본적으로

, 당신의 경우 (팝업) 코드에서 모든 다른 하나에서 도달 할 것

관련 문제