zoukankan      html  css  js  c++  java
  • 事务管理

    private Button home_but_home;
        private Button home_but_sort;
        private Button home_but_cart;
        private Button home_but_user;
        private Fragment[] allfrag;
        private FragmentManager manger;
        private FragmentTransaction trans;

    private void Listener() {
            // TODO Auto-generated method stub
            home_but_home.setOnClickListener(this);
            home_but_sort.setOnClickListener(this);
            home_but_cart.setOnClickListener(this);
            home_but_user.setOnClickListener(this);
        }

    private void fragmanager() {
            // TODO Auto-generated method stub
            //创建fragment
            allfrag = new Fragment[4];
            //获取事务管理
            manger = getSupportFragmentManager();
            allfrag[0] = manger.findFragmentById(R.id.home_fragment_home);
            allfrag[1] = manger.findFragmentById(R.id.home_fragment_sort);
            allfrag[2] = manger.findFragmentById(R.id.home_fragment_cart);
            allfrag[3] = manger.findFragmentById(R.id.home_fragment_user);
            //启动事物
            trans = manger.beginTransaction()
            .hide(allfrag[0])
            .hide(allfrag[1])
            .hide(allfrag[2])
            .hide(allfrag[3]);
            
            trans.show(allfrag[0]).commit();
            
        }

        public void onClick(View v) {
            // TODO Auto-generated method stub
            
            trans = manger.beginTransaction()
            .hide(allfrag[0])
            .hide(allfrag[1])
            .hide(allfrag[2])
            .hide(allfrag[3]);
        
            
            //获取点击按钮的ID
            switch (v.getId()) {
            case R.id.home_but_home:
                
                trans.show(allfrag[0]).commit();
                home_but_home.setBackgroundResource(R.drawable.bottom_tab_home_selected);
                home_but_sort.setBackgroundResource(R.drawable.bottom_tab_classify_normal);
                home_but_cart.setBackgroundResource(R.drawable.bottom_tab_shopping_normal);
                home_but_user.setBackgroundResource(R.drawable.bottom_tab_user_normal);
                home_but_home_tv.setTextColor(Color.RED);
                home_but_sort_tv.setTextColor(Color.BLACK);
                home_but_cart_tv.setTextColor(Color.BLACK);
                home_but_user_tv.setTextColor(Color.BLACK);
                break;
            case R.id.home_but_sort:
                
                trans.show(allfrag[1]).commit();
                home_but_home.setBackgroundResource(R.drawable.bottom_tab_home_normal);
                home_but_sort.setBackgroundResource(R.drawable.bottom_tab_classify_selected);
                home_but_cart.setBackgroundResource(R.drawable.bottom_tab_shopping_normal);
                home_but_user.setBackgroundResource(R.drawable.bottom_tab_user_normal);
                home_but_home_tv.setTextColor(Color.BLACK);
                home_but_sort_tv.setTextColor(Color.RED);
                home_but_cart_tv.setTextColor(Color.BLACK);
                home_but_user_tv.setTextColor(Color.BLACK);
                break;

            case R.id.home_but_cart:
        
                trans.show(allfrag[2]).commit();
                home_but_home.setBackgroundResource(R.drawable.bottom_tab_home_normal);
                home_but_sort.setBackgroundResource(R.drawable.bottom_tab_classify_normal);
                home_but_cart.setBackgroundResource(R.drawable.bottom_tab_shopping_selected);
                home_but_user.setBackgroundResource(R.drawable.bottom_tab_user_normal);
                home_but_home_tv.setTextColor(Color.BLACK);
                home_but_sort_tv.setTextColor(Color.BLACK);
                home_but_cart_tv.setTextColor(Color.RED);
                home_but_user_tv.setTextColor(Color.BLACK);
                break;

            case R.id.home_but_user:
        
                trans.show(allfrag[3]).commit();
                home_but_home.setBackgroundResource(R.drawable.bottom_tab_home_normal);
                home_but_sort.setBackgroundResource(R.drawable.bottom_tab_classify_normal);
                home_but_cart.setBackgroundResource(R.drawable.bottom_tab_shopping_normal);
                home_but_user.setBackgroundResource(R.drawable.bottom_tab_user_selected);
                home_but_home_tv.setTextColor(Color.BLACK);
                home_but_sort_tv.setTextColor(Color.BLACK);
                home_but_cart_tv.setTextColor(Color.BLACK);
                home_but_user_tv.setTextColor(Color.RED);
                break;


            default:
                break;
            }
            
        }

  • 相关阅读:
    基于C#和Asp.NET MVC开发部标视频和苏标主动安全监控平台
    基于Java Netty框架构建高性能的部标808协议的GPS服务器
    交通部796部标平台开发索引
    GPS部标监控平台的功能设计(一)-功能列表
    基于Java Mina框架的部标jt808服务器设计和开发
    基于Asp.NET MVC框架+SignalR +ActiveMQ + Ali OSS 服务构建苏标主动安全智能防控平台
    部标809协议2019版本与2011版本的区别
    出租车Jt/T 905协议与部标1078协议融合的网约车视频监控平台
    基于JT/T 1078协议设计和开发部标视频服务器
    基于Html5+HLS协议播放符合部标1078协议的实时流媒体视频
  • 原文地址:https://www.cnblogs.com/taogev5/p/5659130.html
Copyright © 2011-2022 走看看