여러 개의 팝업을 표시하는 데 문제가 있습니다. 지금 나는 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();
}
}
단지 제안 (팝업) 할 수없는 경우 사용자가 "ok"를 클릭하면 해당 조건으로 작성된 것을 수행 할 함수를 호출합니다. – user2450263