Rodriquez
Rodriquez

Reputation: 1001

How to open first dialogFragment, close it and open next dialogFragment

i dont know how to open next dialog after close one.

How it must work ACTIVITY>FRAGMENT>DIALOG1>DISMISS AND BACK TO ACTIVITY>FRAGMENT>DIALOG2

now work like ACTIVITY>FRAGMENT>DIALOG1>DISMISS AND BACK TO ACTIVITY>FRAGMENT>DIALOG1

So as u see i cant open secound dialog and closed first.

in the fragment i create this:

 private final String DIALOG_WIN = "DialogWinFragment";
    private final String DIALOG_LOST = "DialogLostFragment";
 int pos;
    private final String POSITION = "position";

@OnClick({R.id.btn_buy ,R.id.btn_sell})
public void onGlobalSearchClicked() {
    SharedPreferences prefs = getContext().getSharedPreferences("app.forex", 0);
    SharedPreferences.Editor editor = prefs.edit();
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(DIALOG_LOST);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    if(pos == 0){
        DialogFragment newFragment = DialogLostFragment.newInstance(1);
        newFragment.show(ft, DIALOG_LOST);
        pos = 1;
        editor.putInt(POSITION, pos);
        editor.apply();

    }else if(pos == 1){
        DialogFragment newFragment = DialogWinFragment.newInstance(1);
        newFragment.show(ft, DIALOG_WIN);
        pos--;
    }

}

and in dialog1 i have:

@OnClick({R.id.dialog_lost_frame, R.id.dialog_text_lost})
public void dismissDialogLostFragment(){
    this.dismiss();
    ((CurrencySelectActivity)getContext()).closerGameFragment();
}

how to do this work code guys?

Upvotes: 0

Views: 838

Answers (2)

android_jain
android_jain

Reputation: 798

u can use coundowntimer .You have to deside time for first dialog.

  CountDownTimer waitTimer = new CountDownTimer(6000, 1000) {
    @Override
    public void onTick(long millisUntilFinished) {

        //first dialog
    }

    @Override
    public void onFinish() {
    //second dialog

    }
}.start();

Upvotes: 0

thealeksandr
thealeksandr

Reputation: 1736

In my application I do it like that.

I have and Activity and DialogFragment1 with listener interface. When I create a dialog and set as Listener my current Activity that implements this interface.

DialogFragment1 fragment = new DialogFragment1();
fragment.setListener(this).
fragment.show().

And all necessary actions you make in your Activity and not in DialogFragment.

void onDialogFragment1Action() {
     dialogFragment1.close();
     dialogFragment2.show();
}

Upvotes: 1

Related Questions