How is the Viewflipper handling the back button in Android?
Asked Answered
F

2

6

I'm thinking about using a ViewFlipper for an Wizard like Activity. But I see one problem with this approach. The back button. Will the back button go back to the last shown activity or will the the Viewflipper somehow catch the back button event and only change to the last shown activity?

I suspect the ViewFlipper to be treated as one Activity on the BackStack so is seems that is the wrong aproach for a wizard. Is this correct?

Fitts answered 16/3, 2010 at 13:54 Comment(0)
P
4

ViewFlipper is just a View; it does no special handling of the back button. When you hit the back button on an Activity with a ViewFlipper, it doesn't matter how many times it's flipped, you'll back out of that Activity.

Plus answered 16/3, 2010 at 14:19 Comment(2)
That being said you can catch the back button and use it to unroll the ViewFlipper and then if the ViewFlipper is empty you can back out of the Activity.Howey
True enough, but the Activity guidelines states that you should not take over the back button unless you absolutely need to: developer.android.com/intl/zh-TW/guide/practices/ui_guidelines/…Plus
E
0

@Override public void onBackPressed() {

    int displayedChild = viewFlipper.getDisplayedChild();
    if (displayedChild>0) {
        viewFlipper.setDisplayedChild(displayedChild-1);
    }
    else{
        super.onBackPressed();
    }

}
Estremadura answered 1/10, 2015 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.