我有一个容器A.XML片段至片段交易机器人
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tc.MainActivity"
tools:ignore="MergeRootFrame" />
它是显示选项卡的内容,这是一个列表视图。第一个标签一个是B.XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_height="0dp"
android:layout_width="match_parent"
android:background="@color/lightGrey"
android:layout_weight="0.8"
android:divider="@android:color/transparent"
android:dividerHeight="5.0sp"
android:focusable="false"
android:focusableInTouchMode="false">
</ListView>
</LinearLayout>
内的,当个人的ListView项用户点击,我想与另一个片段即ContentFragment替换当前列表视图。
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
ContentFragment c= new ContentFragment();
c.setArguments(args);
a.getFragmentManager().beginTransaction()
.replace(xxx, c)
.addToBackStack(null)
.commit();
}
对于xxx字段,我想我应该填写a.container?但我怎么能得到它?作为标签A的内部,我是inflater.inflate(R.layout.b,container,false);
取代片段这样吗? –
这是你的活动,应该改变片段。在你的Fragment中,你可以用getActivity()调用活动,然后请求更改Fragment –
R.id.container是错误的,因为我的标签A的布局文件(b.xml)没有id:container,它存在于,xml。 @Arthur_gg,a.getFragmentManager()。beginTransaction()。replace正在做片段更改,其中a是活动。 – Hammer