如何显示连续的对话框弹出窗口? [英] How to show sequential dialog popups?

查看:165
本文介绍了如何显示连续的对话框弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用显示多个弹出窗口有些麻烦。现在我有一个AlertDialog弹出与EditView中的用户将在他们想使该文件,然后我会传递到一个文件对象的名称,然后一个作家和一个新的对话框应该弹出询问用户是否要启动音乐播放器。

不过,由于事已至此,我以后$第一个AlertDialog p $ PSS'确定',绝对没有任何反应。我不知道我在做什么错。任何帮助吗?这是我的code。

  //命名播放列表
    AlertDialog.Builder警报=新AlertDialog.Builder(本);

    alert.setTitle(导出播放列表);
    alert.setMessage(请输入播放列表的名称!);

    //设置一个EditText,以获取用户输入
    最后的EditText输入=新的EditText(本);
    alert.setView(输入);

    alert.setPositiveButton(OK,新DialogInterface.OnClickListener(){
    公共无效的onClick(DialogInterface对话,诠释whichButton){
            NAME = input.getText()的toString()+m3u格式。
            弹出= TRUE;
      }
    });

    alert.setNegativeButton(取消,新DialogInterface.OnClickListener(){
      公共无效的onClick(DialogInterface对话,诠释whichButton){
        // 取消。
      }
    });

    alert.show();


    播放列表命名//后,把歌曲到文件
    如果(弹出){
        弹出= FALSE;
        最终的文件列表=新的文件(mp3folderPath +姓名);
        FileWriter的作家;
        BufferedWriter将写入;

        ArrayList的<字符串>播放列表=新的ArrayList<字符串>();
        Log.d(大便,mAdapter数:+ mAdapter.getCount());
        的for(int i = 0; I< mAdapter.getCount();我++){
            playlist.add(mAdapter.getItem(ⅰ));
        }
        Log.d(大便,playlist.toString());

        //写的歌给m3u播放
        作家=新的FileWriter(名单);
        写=新的BufferedWriter(作家);
        的for(int i = 0; I< playlist.size();我++){
            的String []名= playlist.get(我).split(:);
            Log.d(大便,名字[0]);
            write.append(名称[0] +\ N);
        }
        write.close();

        //弹出窗口
        CharSequence中选择[] =新的CharSequence [] {音乐播放器启动,退出};

        AlertDialog.Builder建设者=新AlertDialog.Builder(本);
        builder.setTitle(导出播放列表!);
        builder.setItems(选择,新DialogInterface.OnClickListener(){

            @覆盖
            公共无效的onClick(DialogInterface对话,诠释它){
                如果(这== 0){
                    意向意图=新的意图(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
                    startActivity(意向);
                    完();
                }
                其他 {
                    完();
                }
            }
        });
    builder.show();
    }
}
 

解决方案

要显示连续弹出,条件和code,连续弹出(S)将不得不从一个到另一个是可达的。照片 AlertDialog1必须包含code这将显示AlertDialog2 ...

尝试是这样的:

  //命名播放列表
                AlertDialog.Builder警报=新AlertDialog.Builder(本);

                alert.setTitle(导出播放列表);
                alert.setMessage(请输入播放列表的名称!);

                //设置一个EditText,以获取用户输入
                最后的EditText输入=新的EditText(本);
                alert.setView(输入);

                alert.setPositiveButton(OK,新DialogInterface.OnClickListener(){
                公共无效的onClick(DialogInterface对话,诠释whichButton){
                    //检查名称不为空
                        NAME = input.getText()的toString()+m3u格式。
                    而不是弹出式//现在= TRUE;
                 //调用FUNC命名播放列表,并在下一个对话框
                        callNextDialog();
                  }
                });

                alert.setNegativeButton(取消,新DialogInterface.OnClickListener(){
                  公共无效的onClick(DialogInterface对话,诠释whichButton){
                    // 取消。
                  }
                });

                alert.show();


                播放列表命名//后,把歌曲到文件
        //如果(弹出){
        //弹出= FALSE;
        //}

                  公共无效callNextDialog(){
最终的文件列表=新的文件(mp3folderPath +姓名);
                    FileWriter的作家;
                    BufferedWriter将写入;

                    ArrayList的<字符串>播放列表=新的ArrayList<字符串>();
                    Log.d(大便,mAdapter数:+ mAdapter.getCount());
                    的for(int i = 0; I< mAdapter.getCount();我++){
                        playlist.add(mAdapter.getItem(ⅰ));
                    }
                    Log.d(大便,playlist.toString());

                    //写的歌给m3u播放
                    作家=新的FileWriter(名单);
                    写=新的BufferedWriter(作家);
                    的for(int i = 0; I< playlist.size();我++){
                        的String []名= playlist.get(我).split(:);
                        Log.d(大便,名字[0]);
                        write.append(名称[0] +\ N);
                        write.close();
                      //弹出窗口
            CharSequence中选择[] =新的CharSequence [] {音乐播放器启动,退出};

                        AlertDialog.Builder建设者=新AlertDialog.Builder(本);
                        builder.setTitle(导出播放列表!);
                        builder.setItems(选择,新DialogInterface.OnClickListener(){

                            @覆盖
                            公共无效的onClick(DialogInterface对话,诠释它){
                                如果(这== 0){
                        意向意图=新的意图(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
                                    startActivity(意向);
                                    完();
                                }
                                其他 {
                                    完();
                                }
                            }
                        });
                    builder.show();
                  }
                }
 

I'm having some trouble with displaying multiple popups. Right now I have an AlertDialog that pops up with an EditView for the user to put in the name of the file they want to make, which I would then pass into a File object and then a Writer and a new Dialog is supposed to pop up asking the user if they want to launch the music player.

However, as things are now, after I press 'Ok' on the first AlertDialog, absolutely nothing happens. I'm not sure what I'm doing wrong. Any help? Here is my code.

    //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();
    }
}

解决方案

To show sequential popup, the conditions and code for consecutive popup(s) would have to be reachable from one to the other.
AlertDialog1 has to contain the code which would show AlertDialog2...

Try something like this:

    //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();
                  }
                }

这篇关于如何显示连续的对话框弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆