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

  • 相关阅读:
    【逆序对】N*M Puzzle / Simple Puzzle
    【逆序对】Ultra
    bzoj 1814 Fornula 1
    hdu 1693 插头dp入门
    bzoj 2154
    没有上司的舞会
    【HNOI】合唱队
    luogu 自适应Simpson2
    luogu 自适应Simpson1
    【bzoj 1502】月下柠檬树
  • 原文地址:https://www.cnblogs.com/taogev5/p/5659130.html
Copyright © 2011-2022 走看看