San*_*ana 3 android android-fragments
我有一个布局
<?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>
Run Code Online (Sandbox Code Playgroud)
在启动时,它确实显示了正确的片段(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());
Run Code Online (Sandbox Code Playgroud)
我曾尝试过删除,替换和添加的所有组合来获取片段的东西,但是徒劳无功!
我还尝试使用代码作为
<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"
>
Run Code Online (Sandbox Code Playgroud)
这确实可以在启动时显示第二个片段!!!!
帮助将在reeally appreicated.
谢谢,
| 归档时间: |
|
| 查看次数: |
6076 次 |
| 最近记录: |