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;
            }
            
        }

  • 相关阅读:
    登录模块(前端bookstrapValidator校验+加密+后台加密+后台验证)
    spring+springmvc+mybatis+redis 实现两重数据缓存
    spring+springmvc+mybatis+redis实现缓存
    获取网页上的所有QQ号码,并生成exel报表
    单点登录(因为原理一样,所以没有实现注销)
    solr 基本命令二(权重查找)
    solr 搭建 (基于solr-5.0.0)
    OC 添加导航栏item
    xcode 一些三方库版本警告 iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.2.99.
    Swift UITextView设置富文本点击, 取消一切点击事件(放大镜/复制粘贴/删除等等)
  • 原文地址:https://www.cnblogs.com/taogev5/p/5659130.html
Copyright © 2011-2022 走看看