经过多天的尝试找到一个双窗格片段与标签的解决方案,我放弃了,并做了我自己的listview,这是在一个X大型平板电脑的布局,并只有片段管理我的标签。我所有的代码除了一部分,我试图删除标签中的旧片段,并根据列表中点击的项目创建一个新的片段。片段没有被删除
这里是生成了标签的片段:
public class AppSectionsPagerAdapter extends FragmentPagerAdapter {
public AppSectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
//THESE FRAGMENTS ARE GENERATED WITH TABS AT START
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
return new DescriptionFragment();
case 1:
return new ImagesFragment();
default:
return new DescriptionFragment();
}
}
在那里我从一个ListView点击添加片段:
public void addfragment() {
//THIS FRAGMENT GOES ON TOP AFTER LISTVIEW CLICK
kick_activity.this.getSupportFragmentManager().popBackStack();
DescriptionFragment fragment = new DescriptionFragment();
android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.container, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();
}
我DescriptionFragment片段:
public static class DescriptionFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section_description, container, false);
text = ((TextView) rootView.findViewById(R.id.description));
text.setText(Html.fromHtml(description_text));
return rootView;
}
我知道我做错了什么,我只是不知道如何解决它。看来,从getItem()创建的片段,当我点击我的listview和addfragment()被调用时,由于没有链接片段,它会覆盖。我可以放在'情况0'而不是'返回新的DescriptionFragment',以便我所有的片段都被链接并且不覆盖?
注 - 当我尝试和使用的getItem ft.repalce()应用程序崩溃,并根据logcat的,它不能找到R.id.container,所以我不能简单地移动代码在
谢谢提前为您提供帮助,我将非常感谢任何解决方案,因为我已经坚持了这几天。
非常感谢! –