我有一个FragmentActivity
在Buttons
它和三个Fragment
类。如果单击按钮 1,我想显示FragmentOne
和隐藏FragmentTwo
, FragmentThree
。如果Button2
被点击,我想显示FragmentTwo
和隐藏FragmentOne
,FragmentThree
反之亦然。我的代码不起作用。
private void fManager() {
FragmentManager manager = getSupportFragmentManager();
f1 = manager.findFragmentById(R.id.first);
f2 = manager.findFragmentById(R.id.second);
f2 = manager.findFragmentById(R.id.third);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
if (b1.isPressed()) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.hide(f2);
transaction.hide(f3);
transaction.show(f1);
transaction.commit();
}
break;
case R.id.button2:
if (b2.isPressed()) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.hide(f1);
transaction.hide(f3);
transaction.show(f2);
transaction.commit();
}
break;
case R.id.button3:
if (b3.isPressed()) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.hide(f1);
transaction.hide(f2);
transaction.show(f3);
transaction.commit();
}
break;
}
}