Android Fragment接口传值
来源:互联网 发布:学生怒骂日本记者知乎 编辑:程序博客网 时间:2024/06/13 14:11
Fragment_A.class
package cn.bgs.fragment_interface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
public class Fragment_A extends Fragment {
private Button mBtn;
private Fragment_Call call;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=View.inflate(getActivity(), R.layout.fragment_a, null);
mBtn=(Button) v.findViewById(R.id.mBtn);
mBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
call.call();
}
});
return v;
}
public void getInter(Fragment_Call call){
this.call=call;
}
}
Fragment_B.class
package cn.bgs.fragment_interface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment_B extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=View.inflate(getActivity(), R.layout.fragment_b, null);
return v;
}
}
Fragment_Call.class
package cn.bgs.fragment_interface;
public interface Fragment_Call {
public void call();
}
XML
activity_main.XML
<LinearLayout 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=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:id="@+id/group"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
fragment_a.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/mBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
</LinearLayout>
fragment_b.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这里是Bfragment"
android:textSize="30sp"
/>
</LinearLayout>
- Android Fragment接口传值
- Android fragment接口通信
- Android Fragment使用接口通信
- Fragment传值接口回调
- fragment传值给activity:接口
- 47 Android fragment 接口回调
- activity和fragment通过接口相互传值
- Fragment向activity传值的接口回调方法
- Fragment静态传值(RecyclerView,接口回调)
- Fragment之间的传值 接口回调
- Android Activity传参数到Fragment中,简单方法不采用接口
- android使用接口回调把fragment把值传回到Activity
- Android fragment 之间传值的方法
- android中fragment之间传值
- Android fragment 与Activity 互相传值。
- Activity通过接口向fragment传数据
- Android学习--可选别名资源和fragment回调接口
- Android 通过接口传值
- C++参考demo-dll
- 安卓EditText输入时自动编号
- 基于Swift的iOS应用程序开发:以Base64字符串形式上传文件——从iOS选择文件并上传
- Java 静态语句块、语句块、构造函数执行顺序
- Android 开发常用的adb命令
- Android Fragment接口传值
- CODECHEF Sereja and Commands
- javaweb学习总结(四)——Http协议
- 数字签名(2):DSA
- Hashmap and Java.io PrintWriter
- Python enumerate
- uva 12168
- 水池数目
- [数据结构]字符串匹配——朴素算法