Fragment事物实现导航页面

来源:互联网 发布:开通淘宝直播什么要求 编辑:程序博客网 时间:2024/06/05 20:13
public class Home_page extends FragmentActivity implements View.OnClickListener {    private TextView home;    private TextView sift;    private TextView my;    private TextView classfly;    private View frag;    private FragmentManager manager;    private List ts;    private List fragments; @Override    public void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.home_page);        //初始化数据        init();    }    private void init() {        //点击侧滑        Drawer();               //将所以实例化Fragment类 添加大集合中        fragments = new ArrayList();        Fragment1 f1 = new Fragment1();        Fragment2 f2= new Fragment2();        Fragment3 f3= new Fragment3();        Fragment4 f4= new Fragment4();        //加入到结合中        fragments.add(f1);        fragments.add(f2);        fragments.add(f3);        fragments.add(f4);        //拿到事物管理者        manager = getSupportFragmentManager();        //通过事物管理者来开启事物        FragmentTransaction beginTransaction = manager.beginTransaction();        //添加到事物中  Id,类        beginTransaction.add(R.id.fragment,f1);        beginTransaction.add(R.id.fragment,f2);        beginTransaction.add(R.id.fragment,f3);        beginTransaction.add(R.id.fragment,f4);        //其他的界面隐藏        beginTransaction.hide(f2);        beginTransaction.hide(f3);        beginTransaction.hide(f4);        //提交事物        beginTransaction.commit();        //数据的控件        initData();    }    private void initData() {        //Fragment 容器        frag = findViewById(R.id.fragment);        //集合存入 TextView 的控件        ts = new ArrayList();        home = (TextView) findViewById(R.id.home);        sift = (TextView) findViewById(R.id.sift);        classfly = (TextView) findViewById(R.id.classfly);        my = (TextView) findViewById(R.id.My);        ts.add(home);        ts.add(sift);        ts.add(classfly);        ts.add(my);        //做点击        home.setOnClickListener(this);        sift.setOnClickListener(this);        classfly.setOnClickListener(this);        my.setOnClickListener(this);    }//使用Fragment事物来做的    @Override    public void onClick(View v) {        //事物管理者来开启事物        FragmentTransaction ft = manager.beginTransaction();        //循环通过 textview集合来来循环        for (int i=0;i

原创粉丝点击