当用户点击导航视图中的第一项
时,将完成以下片段android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
Dashboard newFragment = (Dashboard) fm.findFragmentByTag("viewAlbum");
if (newFragment == null) {
newFragment = new Dashboard();
}
fm.beginTransaction()
.replace(R.id.content_frame, newFragment, "viewAlbum")
.show(newFragment)
.commitAllowingStateLoss();
supportInvalidateOptionsMenu();
当用户点击导航视图中的第二项时,将加载以下片段。
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
AssigneewiseFragment newFragment = (AssigneewiseFragment) fm.findFragmentByTag("viewSelectedPlaylist");
if (newFragment == null) {
newFragment = new AssigneewiseFragment();
}
fm.beginTransaction()
.add(R.id.content_frame, newFragment, "viewSelectedPlaylist")
.show(newFragment)
.addToBackStack(null)
.commitAllowingStateLoss();
问题是,当用户单击导航视图中的第二个项目时,会加载assigneewise片段,但第二个片段下面仍然可以看到第一个片段。我怎样才能解决这个问题?
答案 0 :(得分:1)
使用replace
代替add
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
AssigneewiseFragment newFragment = (AssigneewiseFragment) fm.findFragmentByTag("viewSelectedPlaylist");
if (newFragment == null) {
newFragment = new AssigneewiseFragment();
}
fm.beginTransaction()
.replace(R.id.content_frame, newFragment, "viewSelectedPlaylist")
.show(newFragment)
.addToBackStack(null)
.commitAllowingStateLoss();
答案 1 :(得分:1)
我不认为replace()会解决您的问题
为此你需要将背景颜色设置为白色或任何东西,你需要在主要布局上使用点击监听器。