博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
事务管理
阅读量:7024 次
发布时间:2019-06-28

本文共 3413 字,大约阅读时间需要 11 分钟。

 

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

转载于:https://www.cnblogs.com/taogev5/p/5659130.html

你可能感兴趣的文章
sqlserver临时表或表变量代替游标
查看>>
零拷贝概念 -- linux内核
查看>>
iOS 新浪微博-2.0 搜索框/标题带箭头/下拉菜单
查看>>
Windows平台的Eclipse-javaEE-mars相关配置
查看>>
Jquery UI的datepicker插件使用
查看>>
ffmpeg无法接收组播流问题处理
查看>>
Nginx SSL+tomcat集群,request.getScheme() 取到https正确的协议
查看>>
prototype.js 和 jQuery.js中 ajax 的使用
查看>>
java_selenium 开发环境搭建
查看>>
中国的手写输入法iOS8.1在崩溃
查看>>
easyui-layout个人实例
查看>>
Java、PHP训练场地选择成都传祺播客
查看>>
LeetCode——Jump Game
查看>>
Codeforces 106D Treasure Island 预处理前缀+暴力(水
查看>>
Android/iOS微信6.3.5同时发布更新 支持群视频聊天、群公告
查看>>
【转】android ddms中查看线程释疑
查看>>
ecshop广告-》单张,多张
查看>>
Eclipse混淆文件导入Android Studio Gradle编译报input jar file is specified twice
查看>>
[redis] 分布式 Redis 的 CRUD 实现
查看>>
-Dmaven.multiModuleProjectDirectory system propery is not set.
查看>>