片段更新我的用新片段的Android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content" >
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="wrap_content">
<LinearLayout android:id="@+id/linearLayout13" android:layout_height="wrap_content" android:paddingRight="70dp" android:orientation="vertical" android:paddingLeft="70dp" android:layout_width="wrap_content">
<ImageView android:id="@+id/baby_icon" android:layout_height="wrap_content" android:src="@drawable/baby" android:clickable="true" android:layout_width="wrap_content"></ImageView>
</LinearLayout>
</LinearLayout>
<fragment
android:name="com.nicu.health.FragAFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/yellow_cardlist_fragment"
android:layout_weight="1"
>
</fragment>
</LinearLayout>
布局在启动这确实显示正确的片段(FragAFragment)。现在按钮点击baby_icon
我尝试删除当前片段并添加一个新的(FragBFragment),它具有完全不同的布局。
虽然我看到onCreateView
方法被调用,它确实返回一个非空视图,但新片段屏幕上的UI没有更新。我使用下面的代码来更新片段。
Fragment baby = FragBFragment.newInstance(1);
FragmentTransaction ft = getFragmentManager().beginTransaction();
// ft.remove(getFragmentManager().findFragmentById(R.id.yellow_cardlist_fragment));
// ft.add(R.id.yellow_cardlist_fragment, baby);
ft.replace(R.id.yellow_cardlist_fragment, baby);
ft.addToBackStack(null);
Log.i(TAG, "Code for commit = "+ft.commit());
我已经尝试删除,替换和添加的所有组合,以获得片段的事情,但徒劳无功!
而且还我试图与代码
<fragment
android:name="com.nicu.health.FragBFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/yellow_cardlist_fragment"
android:layout_weight="1"
>
,这是否工作在启动时显示的第二个片段!!!!
帮助将reeally appreicated。
感谢,