Android 在FragmentTabHost中更改选项卡后,ListFragment不可单击
我的android应用程序按以下方式组织:Android 在FragmentTabHost中更改选项卡后,ListFragment不可单击,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我的android应用程序按以下方式组织: 包含两个片段的FragmentTabHost(第一个选项卡中的FragmentA和第二个选项卡中的FragmentB) FragmentA有一个ListViewFragment并膨胀以下视图: <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id
- 包含两个片段的FragmentTabHost(第一个选项卡中的FragmentA和第二个选项卡中的FragmentB)
- FragmentA有一个ListViewFragment并膨胀以下视图:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/titles" android:name="br.sachetto.ondepublicar.ListViewFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="false" android:focusableInTouchMode="false" android:clickable="false" />
有人能帮我解决这个问题吗?如果我没弄错的话,您可以将一个片段膨胀成一个以前(用xml)定义为静态/编译时片段的片段
这种做法是不允许的,可能会导致两个碎片相互重叠。我建议您将所有碎片充气,这些碎片将通过代码动态移动或更改。您是对的,这是不允许的。我的主要想法是制作一个标题详细信息应用程序,如下所述:。这就是为什么我把一个碎片放在另一个里面。最大的问题是tabHost只接受片段。否则,我会将FragmentA作为一个FragmentA活动。有没有不使用嵌套片段的方法来实现这一点?我找到了一个基于嵌套片段的解决方案:
private static View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null)
parent.removeView(view);
}
else {
view = inflater.inflate(R.layout.list_fragment,
container, false);
}
}
return view;
}