有人可以更清楚地说明如何在同一个选项卡中拥有多个 View 吗?我有 3 个标签。 我使用 FragmentActivity 加载第一个选项卡的内容,这是一个 ListFragment。单击列表中的任何项目时,必须显示另一个子项目列表。为此,我使用了一个内部静态 FragmentActivity 类,它又动态添加了一个显示新列表的新 fragment 。但是在新的 Fragment 中,我看不到我的第一个标签。
如何在 Fragment 或 View 之间切换以保持 Tab 完好无损?
仍然无法实现...我的代码如下:
public void onListItemClick(ListView l, View v, int position, long id)
{
getListView().setItemChecked(position, true);
DetailsFragment details = (DetailsFragment)
getFragmentManager().findFragmentById(R.id.titles);
if (details == null || details.getShownIndex() != position)
{
details = DetailsFragment.newInstance(position);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.titles, details);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
}
布局文件如下:
<?xml version="1.0" encoding="utf-8"?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="com.example.myapp.NewReqScrLoader$TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
我哪里出错了吗?
最佳答案
您应该将第一个 ListFragment 替换为另一个使用子项构建的 List FRagment。不要创建新的 FragmentActivity。
使用 transaction.replaceFragment(..) 来做到这一点。
关于android - 单标签多 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8969580/