一起Talk Android吧(第二百五十回:Android中Fragment之间的数据传递大结局二)

各位看官们大家好,上一回中咱们说的是Android中Fragment之间数据传递的例子,这一回咱们继续说该例子。闲话休提,言归正转。让我们一起Talk Android吧!

看官们,上一回中我们只列出了ActivityA,ActivityB,FragmentA1,FragmentA2,FragmentB文件中代码,代码比较多,因此只列出这些Java代码,本章回中我们将列出也这些代码匹配的布局文件代码,它们是activity_a,activity_b,fragment_a1,fragment_a2,fragment_b,代码的类型都是xml类型的布局文件,请大家参考:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ActivityA">

    <TextView
        android:text="This is Activity A"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/start_activity_b"
        android:text="Start Activity B"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/start_activity_b_for_data"
        android:text="Start Activity B For Data"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@+id/frag_a1"
        android:layout_width="match_parent"
        android:layout_height="36dp">

    </FrameLayout>

    <FrameLayout
        android:id="@+id/frag_a2"
        android:layout_width="match_parent"
        android:layout_height="36dp">
    </FrameLayout>

    <Button
        android:id="@+id/fraga1_to_a2"
        android:textAllCaps="false"
        android:text="Fragment A1 send data to Fragment A2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/fraga2_to_a1"
        android:textAllCaps="false"
        android:text="Fragment A2 send data to Fragment A1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ActivityB">

    <TextView
        android:text="This  is Activity B"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@+id/frag_b"
        android:layout_width="match_parent"
        android:layout_height="36dp">

    </FrameLayout>

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentA1">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/fraga1_tv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Fragment A1" />

</FrameLayout>

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentA2">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/fraga2_tv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="FragmentA2" />

</FrameLayout>

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentB">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/fragb_tv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="FragmentB" />

</FrameLayout>

各位看官,关于Android中Fragment之间数据传递的例子咱们就介绍到这里,欲知后面还有什么例子,且听下回分解!

猜你喜欢

转载自blog.csdn.net/talk_8/article/details/106972397