我在一个片段中有 4 个按钮。当我单击一个按钮“A”时,会加载一个片段。当点击按钮“B”时,另一个片段被加载,依此类推。我的问题是当我再次单击按钮时,新片段正在加载。我想从 backStack 加载前一个片段。
if(rootView.findViewById(R.id.talk_main_container)!=null){
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Bundle bundle=new Bundle();
bundle.putString("cityid", cityId);
if(position == 1){
MainForumsFragment mTalkNewFragment = new MainForumsFragment();
mTalkNewFragment.setArguments(bundle);
transaction.replace(R.id.talk_main_container, mTalkNewFragment);
}
if(position == 2){
TalkNewFragment mTalkNewFragment = new TalkNewFragment();
mTalkNewFragment.setArguments(bundle);
transaction.replace(R.id.talk_main_container, mTalkNewFragment);
}
if(position == 3){
TalkNewFragment mTalkNewFragment = new TalkNewFragment();
mTalkNewFragment.setArguments(bundle);
transaction.replace(R.id.talk_main_container, mTalkNewFragment);
}
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
transaction.addToBackStack(null);
transaction.commit();
}
那么我该如何实现呢?