简体   繁体   中英

Restoring Fragment view when pressing back

I have two fragments on the screen and one button. When I press the button, one of the fragments hides and the other fragment changes a little bit its UI (a textview is hidden).

I store this transaction in the backstack so when the user presses back, the hidden fragment shows again. However I don't know how to tell the other fragment (the one that's always been visible) to show again the textview because this change is not part of the transaction.

Any ideas? thanks!

Overwrite onBackPressed() of your FragmentActivity in a similar way:

@Override
public void onBackPressed() {
    super.onBackPressed();
    if (mTextView.getVisibility() == View.GONE) {
        mTextView.setVisibility(View.VISIBLE);
    }
}

Or use some flag which you can set when you press your button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM