Peter Sun
Peter Sun

Reputation: 1845

Dialog to open another dialog

I want to followup with a dialog if a person chooses a specific answer after answering a choice question with a dialog.

In this example, if the person chooses 'Choice1' then another dialog should open to ask more questions.

I have the following partial code below:

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

If I can't do it this way. How would you go about doing this? Thanks in advance. I am continuing to learn more as I work on this... thanks for all the help

Upvotes: 4

Views: 5775

Answers (1)

Plato
Plato

Reputation: 2348

Just complete your second method like

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

Upvotes: 3

Related Questions