Fragment的增删改以及显示、隐藏操作
来源:互联网 发布:g900 支持 mac 编辑:程序博客网 时间:2024/05/17 01:18
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_manage_fragment" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingBottom="16dp" android:paddingTop="16dp" tools:context="com.studio.fragmentdemo.ManageFragmentActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="add" android:text="Add Fragment"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="remove" android:text="Remove Fragment"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="replace" android:text="replace Fragment"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="hide" android:text="hide Fragment"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="show" android:text="show Fragment"/> <FrameLayout android:id="@+id/fl_container" android:layout_width="wrap_content" android:layout_height="wrap_content"/></LinearLayout>
package com.studio.fragmentdemo;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTransaction;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class ManageFragmentActivity extends AppCompatActivity { private FragmentManager fragmentManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_manage_fragment); } public void add(View view){ fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); FragmentTest fragmentTest = new FragmentTest(); transaction.add(R.id.fl_container,fragmentTest,"fragment"); transaction.commit(); } public void remove(View view){ FragmentTransaction transaction= fragmentManager.beginTransaction(); transaction.remove(fragmentManager.findFragmentByTag("fragment")); transaction.commit(); } public void replace(View view){ FragmentTransaction transaction = fragmentManager.beginTransaction(); AnotherFragmentTest anotherFragmentTest = new AnotherFragmentTest(); transaction.replace(R.id.fl_container,anotherFragmentTest); transaction.commit(); } public void hide(View view){ FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.hide(fragmentManager.findFragmentByTag("fragment")); transaction.commit(); } public void show(View view){ FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.show(fragmentManager.findFragmentByTag("fragment")); transaction.commit(); }}
阅读全文
0 0
- Fragment的增删改以及显示、隐藏操作
- fragment的增删改
- fragment的增删改
- MySql的增删改查以及常用的一些操作
- XML解析以及增删改查的操作 1
- XML解析以及增删改查的操作 2
- XML解析以及增删改查的操作 3
- XML解析以及增删改查的操作 4
- XML解析以及增删改查的操作 5
- XML解析以及增删改查的操作6
- js数组以及json元素的操作-增删改查
- 显示数据列表,并能进行增删改的操作
- fragment的显示 隐藏
- 获取网络状态以及Fragment的隐藏和显示使用
- 通用的增删改操作
- 二叉排序树的增删改操作
- Ecmall 的增删改操作
- MongodbTemplate的增删改操作
- Android系统--输入系统(十七)Dispatcher线程_分发dispatch
- Cartographer 参数调试
- FPGA时钟
- UVA
- lua教程二
- Fragment的增删改以及显示、隐藏操作
- ROS语音学习
- java开发一个一GMT(格林威治标准时间)来显示当前时间的程序
- Unity和android的交互流程
- 在toString()方法中千万不要使用this
- spingboot之静态资源处理配置
- windows10 编译x264出现 undefined reference to `_beginthreadex'解决
- dirty_page writeback caused task hang
- 如何动态改变form表单的action