我有分类列表的片段。此列表中的项目如下所示。我需要在此列表的元素上单击以通过将占位符替换为CategoryListFragment的新实例来显示子类别。如何使用FragmentManager替换那个场景?
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/category_item_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:layout_below="@+id/category_item_name"
android:id="@+id/subcategories_fragment_placeholder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
片段
public class CategoryListFragment extends android.support.v4.app.ListFragment {
public static CategoryListFragment create(Category parent) {
CategoryListFragment f = new CategoryListFragment();
...
return f;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
FrameLayout placeholder = (FrameLayout) v.findViewById(R.id.subcategories_fragment_placeholder);
CategoryListFragment subs = CategoryListFragment.create(adapter.getItem(position));
getChildFragmentManager().beginTransaction()...
// ???
}
}