package com.example.ren.dz; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; import android.view.Window; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.Toast; import fragment.faxian_fragment; import fragment.shouye_fragment; import fragment.zhouwei_fragment; import fragment.ziji_fragment; /** * Created by ren on 2016/3/9. */ public class Main_Ac extends FragmentActivity implements OnCheckedChangeListener { private View fragment; private RadioGroup radioGroup; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏 setContentView(R.layout.welcome); fragment = findViewById(R.id.fragment_home); radioGroup = (RadioGroup) findViewById(R.id.radiogroup_home); radioGroup.setOnCheckedChangeListener(this); } @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); switch (i) { case R.id.zhuye: Toast.makeText(Main_Ac.this, "主页", Toast.LENGTH_SHORT).show(); shouye_fragment er = new shouye_fragment(); ft.replace(R.id.fragment_home, er); ft.commit(); break; case R.id.faxian: Toast.makeText(Main_Ac.this, "发现", Toast.LENGTH_SHORT).show(); faxian_fragment yi = new faxian_fragment(); ft.replace(R.id.fragment_home, yi); ft.commit(); break; case R.id.zhouwei: Toast.makeText(Main_Ac.this, "周围", Toast.LENGTH_SHORT).show(); zhouwei_fragment san = new zhouwei_fragment(); ft.replace(R.id.fragment_home, san); ft.commit(); break; case R.id.ziji: Toast.makeText(Main_Ac.this, "自己", Toast.LENGTH_SHORT).show(); ziji_fragment si = new ziji_fragment(); ft.replace(R.id.fragment_home,si); ft.commit(); break; } } }
Fragment切换
最新推荐文章于 2023-11-12 21:50:19 发布