通过容器方式添加 fragment的删除
来源:互联网 发布:网络销售话术流程 编辑:程序博客网 时间:2024/06/07 06:13
<RelativeLayout 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" android:gravity="center" tools:context="${relativePackage}.${activityClass}" > <Button android:id="@+id/btnMain" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btnmain"/> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btnmain" android:layout_below="@id/btnMain" android:onClick="btn2_click"/> <TextView android:id="@+id/tvcenter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:layout_centerHorizontal="true" android:layout_below="@id/btn2"/> <FrameLayout android:id="@+id/ly1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/tvcenter" /><FrameLayout android:id="@+id/ly2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/ly1" /></RelativeLayout>
package com.pipashu.todolist;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTransaction;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends FragmentActivity {FragmentManager fm;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);fm=getSupportFragmentManager();Button btn=(Button)findViewById(R.id.btnMain);btn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//增FragmentTransaction fts= fm.beginTransaction();fts.add(R.id.ly1,new Fragment1());fts.commit();}});}public void btn2_click(View v){//删FragmentTransaction fts= fm.beginTransaction();Fragment fratemp=fm.findFragmentById(R.id.ly1); //通过查找容器的id来找到该fratempfts.remove(fratemp);fts.commit();}}
0 0
- 通过容器方式添加 fragment的删除
- Android Fragment的增加,删除,添加
- Android Fragment的增加,删除,添加
- vector顺序容器的添加与删除
- 添加Fragment的两种方式
- 使用Kotlin的方式添加Fragment
- 添加Fragment的两种方式
- STL容器删除的正确打开方式
- 删除容器对象的几种方式
- 通过上下文菜单的方式进行删除添加日记的操作
- Android Fragment的动态添加,Fragment,Activity以及Fragment之间的通信方式
- solr 通过URL的方式删除索引
- solr 通过URL的方式删除索引
- Viewpager动态添加删除Fragment
- viewpager+fragment 动态添加删除
- viewpager+fragment 动态添加删除
- 动态修改viewpager里面的fragment(添加和删除)
- ViewPager Fragment动态添加以及动态删除的理解
- Spring (本人小白,初学spring ,欢迎各位大神指点)
- 步步为零
- PAT(A) 1031
- 【BZOJ】2049 [Sdoi2008]Cave 洞穴勘测 LCT入门题
- Android应用开发相关下载资源
- 通过容器方式添加 fragment的删除
- Python中文乱码
- Android 自动化测试(4)<uiautomator>
- 3xian教主的警世良言兼退役贴
- TMS IntraWeb 5.4.1.1 for XE6 (适配Intraweb14.0.32)
- 以锚点为基础进行旋转
- 第八周项目四 个人所得税
- 看看别人是怎么写程序的(程序员的自我修养)
- 楼教主的ACM心路历程