在按钮上显示和隐藏片段单击

时间:2012-11-19 13:32:45

标签: android android-fragments

我正在开发一个由Fragment组成的应用程序,当我点击它应该显示和隐藏的按钮时。默认情况下,我将片段设置为可见性消失,即使这对我来说也不起作用:

FragmentTransaction  mFragmentTransaction = getFragmentManager().beginTransaction();
mMenuFragment = new MenuFragment();
mFragmentTransaction.add(R.id.frmMenuBar, mMenuFragment); 
mFragmentTransaction.hide(mMenuFragment);
mFragmentTransaction.addToBackStack(null);
mFragmentTransaction.commit();

下面的代码我一直按下按钮。

@Override
protected void onMenuButtonClick(View Button) {
super.onMenuButtonClick(Button);
System.out.println("Botton Clciked");

if (Button.isClickable()) {
    FragmentTransaction menuTransaction = getFragmentManager().beginTransaction();
    menuTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    menuTransaction.show(mMenuFragment);
    menuTransaction.addToBackStack(null);
    menuTransaction.commit();
} else {
    FragmentTransaction menuShowTransaction = getFragmentManager().beginTransaction();
    menuShowTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    menuShowTransaction.hide(mMenuFragment);
    menuShowTransaction.addToBackStack(null);
    menuShowTransaction.commit();
}
}

请任何人帮助我。

0 个答案:

没有答案