0

在一Activity类中,我使用不同的布局。

通过禁用一种布局,我正在转向另一种布局。但是我在按下后退按钮时遇到了问题。当我处于第三个布局时,它会进入第一个布局。

这是我的代码:

我使用了 3 个按钮来移动到另一个布局。

public void continueToDelivery(View view) {
    relativeLayoutLogin.setVisibility(view.GONE);
    relativeLayoutDelivery.setVisibility(view.VISIBLE);
    relativeLayoutPayment.setVisibility(view.GONE);  
}   

public void continueToPayment(View view) {
    relativeLayoutDelivery.setVisibility(view.GONE);
    relativeLayoutPayment.setVisibility(view.VISIBLE);
}

public void placeOrder(View view) {
    relativeLayoutPayment.setVisibility(view.GONE);
    relativeLayoutSuccess.setVisibility(view.VISIBLE);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
    {
        onBackPressed();
    }
    return super.onKeyDown(keyCode, event);
}
4

1 回答 1

1

然后覆盖onBackPressed您的活动:

 @Override
    public void onBackPressed() {
      if(isThirdLayoutVisible)
       //go to second layout
      else if(isSecondLayoutVisible)
      //go to first layout
     else 
     //exit from app
    }
于 2015-07-06T11:18:14.380 回答