簡體   English   中英

對話框打開另一個對話框

[英]Dialog to open another dialog

如果一個人在用對話框回答選擇問題后選擇一個特定的答案,我想跟進一個對話框。

在此示例中,如果此人選擇“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
            }           
        });
}   

如果我不這樣做的話。 你會怎么做呢? 提前致謝。 我正在繼續學習更多知識,感謝所有的幫助

剛剛完成你的第二種方法

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM