0

In my app I need multiple dialogs or multiple views which will be updated after clicking positive and negative dialog buttons.

How should it looks in example:

1) Call first Dialog1

2) Inside Dialog1 I have some data and 2 buttons (positive and negative) onClick possitive Button I go to next Dialog2 on negative I exit dialogs.

3) Inside Dialog2 similar situation click on possitive button provides me to next dialog or dialog view but negative button leeds back to Dialog1

for now my code looks like :

public class DialogChoiceActivity extends DialogFragment {

    LayoutInflater inflater;
    View v;

    public Dialog onCreateDialog(Bundle savedInstanceState) {


        inflater = getActivity().getLayoutInflater();
        v = inflater.inflate(R.layout.dialog_email,null);
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        final Dialog dialog2 = builder.create();
        builder.setTitle("Email " + " 1/10");
        builder.setView(v).setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        }).setNegativeButton("Exit", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        return builder.create();
    }

First of all I'm not sure which way is better create multiple dialogs or one Dialog with multiple Views. Which way is better if I want easily move from one dialog to another (or view). There are some problems because I cant update builder object or dissmiss it so how shold all this looks like ? what is best way to do that

Sorry for chaotic and weak language.

  • Maybe you can achieve this creating a ViewPager inside your DialogFragment and creating individual fragments for each view. – miibpa May 09 '17 at 09:20

1 Answers1

0

Create DialogFragment as you needed.

Make clicking on the positiveButton to show next dialog and dismiss current dialog.

From next dialog, clicking on negativeButton to show previous dialog and dismiss current one.

  • It doesn't work. First of all can't dismiss 'AlertDialog.Builder builder', second it doesn't show my previous dialog –  May 09 '17 at 10:09
  • Not dismissing builder, in button onClick method use dialog.dismiss() –  May 09 '17 at 10:11
  • how should this looks ? Should I create new dialog object using this builder ? –  May 09 '17 at 10:17
  • I said to create numbers of DialogFragment you want to. Each fragment has its own builder. –  May 09 '17 at 10:21
  • If I do that I can't back to first one –  May 09 '17 at 10:35
  • Since they are separated fragments, you can show whatever fragments you want to. Set second fragment's negative button to show first one. –  May 09 '17 at 10:37