Back to parent view when press on escape
I am using ViewFlipper for my application. I trying to make it : when user pressed on escape (back) button, it would be back to parent Layout.
In other words, just like this :
Activity
|
La开发者_Python百科yout1 -> Layout2 -> Layout3
if user pressed on escape, go back to parent:
Layout1 <- Layout2 <- Layout3
How to make it ?
Please advice.
Thanks.
You might find this useful: Back and the other Hard Keys - three stories
Have you tried ViewFlipper.showNext() and ViewFlipper.showPrevious()?
You will need to handle KeyEvent with KEYCODE_BACK something like ( in your activity):
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK:
if (/*has more views to show*/){
viewFlipper.showPrevious();
return true
}else{
return super.dispatchKeyEventt(event)
}
//rest of the code here
精彩评论