Janusz
Janusz

Reputation: 189474

How is the Viewflipper handling the back button in Android?

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?

Upvotes: 6

Views: 2437

Answers (2)

hugerde
hugerde

Reputation: 949

@Override public void onBackPressed() {

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

}

Upvotes: 0

Dan Lew
Dan Lew

Reputation: 87440

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.

Upvotes: 4

Related Questions