当前位置:网站首页>Fragment's show and hide
Fragment's show and hide
2022-08-10 13:20:00 【sharp】
package kk.com.yuekao; import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTransaction;import android.widget.RadioGroup; import com.bawei.fragment.Fragment1;import com.bawei.fragment.Fragment2;import com.bawei.fragment.Fragment3; public class MainActivity extends FragmentActivity {private RadioGroup group;private Fragment1 fragment1;private Fragment2 fragment2;private Fragment3 fragment3;private FragmentTransaction transactiontransaction;private FragmentManager supportFragmentManager; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//Get the resource IDgroup=findViewById(R.id.group);//Method of loading Fragment//get the management classsupportFragmentManager = getSupportFragmentManager();fragment1 = new Fragment1();fragment2 = new Fragment2();fragment3 = new Fragment3();//Open thingstransactiontransaction = supportFragmentManager.beginTransaction();//Load Fragmenttransactiontransaction.add(R.id.fragm,fragment1);transactiontransaction.add(R.id.fragm,fragment2);transactiontransaction.add(R.id.fragm,fragment3);// show and hidetransactionransaction.show(fragment1).hide(fragment2).hide(fragment3);transactiontransaction.commit();group.check(group.getChildAt(0).getId()); //group monitorgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {FragmentTransaction FragmentTransaction1= supportFragmentManager.beginTransaction();switch (checkedId){case R.id.but1:fragmentTransaction1.show(fragment1).hide(fragment2).hide(fragment3);break;case R.id.but2:fragmentTransaction1.show(fragment2).hide(fragment1).hide(fragment3);break;case R.id.but3:fragmentTransaction1.show(fragment3).hide(fragment2).hide(fragment1);break;} } }fragmentTransaction1.commit();} }});} }}
————————————————
版权声明:本文为CSDN博主「Fahaxiki丿」的原创文章,遵循CC 4.0 BY-SACopyright agreement, reprint please attach the original source link and this statement.
Original link: https://blog.csdn.net/wangshuo_/article/details/86229990
边栏推荐
猜你喜欢
随机推荐
【mysql索引实现原理】
【jstack、jps命令使用】排查死锁
啥?他一个人写了个价值100万的软件,却用来开源了!
shell:正则表达式及三剑客grep命令
【学习笔记】Redis的持久化
es6-promise对象详解
娄底石油化工实验设计、建设规划概述
C# InitializeComponent() does not exist in the current context
LeetCode medium topic search of two-dimensional matrix
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
Detailed explanation of es6-promise object
22家!北京昌平区通报存在食品安全问题餐饮服务企业
Codeforces Round #276 (Div. 1) D. Kindergarten
矩阵键盘&基于51(UcosII)计算器小项目
3DS MAX 批量导出文件脚本 MAXScript 带界面
C#报错 The ‘xmins‘ attribute is not supported in this context
How to cultivate the design thinking of ui designers?
Requirements for the construction of Loudi stem cell preparation laboratory
Pod生命周期
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]