【问题标题】:Dialog to open another dialog对话框打开另一个对话框
【发布时间】:2017-07-31 07:33:07
【问题描述】:

如果有人在用对话回答选择题后选择了特定答案,我想用对话跟进。

在此示例中,如果此人选择“Choice1”,则应打开另一个对话框以询问更多问题。

我有以下部分代码:

private void openDialog1()
{
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Select Choice");
    builder.setSingleChoiceItems(ChoiceLists.listofchoices,-1,new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int item)
            {
                ccRewardDialog.dismiss();
                String finalString = "";
                if((ChoiceLists.listofchoices[item].equals("Choice1")) || (ChoiceLists.listofchoices[item].equals("Choice2"))) 
                {
                    openDialog2();
                }
                TextView tv1 = (TextView) getActivity().findViewById(R.id.tv1);
                finalString = ChoiceLists.strRewards[item];
                if(!RESULT.equals("")) //RESULT being a global value
                {
                    finalString = finalString + "-" + RESULT;
                    RESULT = "";
                }
                tv1.setText(tv1.getText() + finalString + "\n");                

            }
        });
    dialog1 = builder.create();
    dialog1.show();
}

private void openDialog2()
{
    LayoutInflater li = LayoutInflater.from(getActivity());
    View promptView = li.inflate(R.layout.reward_detail_prompt, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(promptView);
    final EditText userInput = (EditText) promptView.findViewById(R.id.etRewardDetail);
    builder.setCancelable(false);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int id) 
            {
                RESULT = userInput.getText().toString();
            }
        });
    builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int which) 
            {
                RESULT = ""; //RESULT being a global value
            }           
        });
}   

如果我不能这样做。你会怎么做呢?提前致谢。我正在继续学习更多信息...感谢所有帮助

【问题讨论】:

标签: android android-alertdialog


【解决方案1】:

只需完成您的第二种方法,例如

private void openDialog2()
{
 ...
 builder.create().show();
}

【讨论】:

    猜你喜欢
    • 2015-12-30
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    相关资源
    最近更新 更多