Fragment高级进阶
一、pandas是什么?
代码演示:
radioGroupId.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.person_id:
manager = getSupportFragmentManager();
fragmentTransaction = manager.beginTransaction();
fragmentTransaction.add(R.id.frame_layout_id,new FristFragment());
fragmentTransaction.addToBackStack("11");
fragmentTransaction.commit();
break;
case R.id.message_id:
manager = getSupportFragmentManager();
manager.popBackStack();
SelectActivity.this.fragmentTransaction = manager.beginTransaction();
SelectActivity.this.fragmentTransaction.replace(R.id.frame_layout_id,new SecondFragment());
SelectActivity.this.fragmentTransaction.commit();
break;
default:
break;
}
}
});
case R.id.message_id:
manager = getSupportFragmentManager();
fragmentTransaction = manager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout_id,new SecondFragment());
fragmentTransaction.commit();
break;
Fragment 传值介绍
不同页面间传值是最基本的要求.(这是页面间的联动,交互) |
请看需求
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3cd61a17c43c3b314c0ff473b9117243.png)
activity 给 fragment传值
主要涉及到一个方法是getArguments()和setArguments(). 一个设置属性值,一个去取属性值. |
步骤: 要传的值,放到bundle对象里; 在Activity中创建该Fragment的对象fragment,通过调用 fragment.setArguments()传递到fragment中; 然后更新fragment. 在该Fragment中通过调用getArguments()得到bundle对象,就能得到里面的值。 |
xml的activity
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="来吧传点啥"
android:id="@+id/fg_et"></EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button_fg"
android:text="点我试一试"
android:onClick="click"></Button>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ll"></LinearLayout>
</LinearLayout>
这个是Fragmentxml布局页面