当前位置:网站首页>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

原网站

版权声明
本文为[sharp]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208101237546115.html