前言
Activity
与Fragment
的使用在Android
开发中非常多- 今天,我将主要讲解
Activity
与Fragment
如何进行通信,实际上是要解决两个问题:Activity
如何传递数据到Fragment
?Fragment
如何传递数据到Activity
?
问题1: Activity 如何传递数据到 Fragment?
采用Bundle
方式 activity传值fragment
采用接口回调方式 fragment传值给activity
activity_main.xml 布局
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.bwie.ceshi.MainActivity">
<TextView
android:id