一起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之间数据传递的例子咱们就介绍到这里,欲知后面还有什么例子,且听下回分解!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

talk_8

真诚赞赏,手有余香

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值