选择 listFragment A 项目后,我想用片段 B2 替换片段 B1。
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Integer Position = position;
WebViewerFragment fragment = (WebViewerFragment) getFragmentManager()
.findFragmentById(R.id.detailFragment);
if (Position.equals(0)) {
FragmentManager fm = getFragmentManager();
WebViewerFragment newFragment = new WebViewerFragment();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.detailFragment, newFragment);
ft.addToBackStack("android");
ft.commit();
} else if (Position.equals(1)) {
FragmentManager fms = getFragmentManager();
WebViewerFragment_II newFragments = new WebViewerFragment_II();
FragmentTransaction fts = fms.beginTransaction();
fts.replace(R.id.detailFragment, newFragments);
fts.addToBackStack("google");
fts.commit();
}
}
它只替换一次,在选择项目 1(位置 0)后应用程序再次崩溃。