• Fragment的隐藏与显示


    package com.bwie.helpdemo;
    
    import com.bwie.fragment.BillFrag;
    import com.bwie.fragment.IndexFrag;
    import com.bwie.fragment.TaskFrag;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.SharedPreferences;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentTransaction;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class IndexActivity extends FragmentActivity implements OnClickListener {
    
        private Button index_bill;
        private TextView index_home;
        private TextView index_task;
    
        private IndexFrag indexFrag;
        private BillFrag billFrag;
        private TaskFrag taskFrag;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_index);
            
            // 找控件
            findView();
    
            // 为布局添加fragment,开启事物
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction tran = fm.beginTransaction();
    
            indexFrag = new IndexFrag();
            billFrag = new BillFrag();
            taskFrag = new TaskFrag();
            //R.id.relative为布局
            tran.add(R.id.relative, indexFrag, "index").show(indexFrag)
            .add(R.id.relative, billFrag, "bill").hide(billFrag)
            .add(R.id.relative, taskFrag, "task").hide(taskFrag);
    
            tran.commit();
    
            // 为按钮设置点击监听
            index_bill.setOnClickListener(this);
            index_home.setOnClickListener(this);
            index_task.setOnClickListener(this);
        }
    
        private void findView() {
            index_bill = (Button) findViewById(R.id.index_bill);
            index_home = (TextView) findViewById(R.id.index_home);
            index_task = (TextView) findViewById(R.id.index_task);
    
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
            case R.id.index_bill:
                // 获取事物
                FragmentManager fm_1 = getSupportFragmentManager();
                FragmentTransaction tran_0 = fm_1.beginTransaction();
                tran_0.show(billFrag).hide(indexFrag).hide(taskFrag).commit();
    
                break;
    
            case R.id.index_home:
                FragmentManager fm_2 = getSupportFragmentManager();
                FragmentTransaction tran_1 = fm_2.beginTransaction();
                tran_1.show(indexFrag).hide(billFrag).hide(taskFrag).commit();
    
                break;
            case R.id.index_task:
                FragmentManager fm_3 = getSupportFragmentManager();
                FragmentTransaction tran_2 = fm_3.beginTransaction();
                tran_2.show(taskFrag).hide(billFrag).hide(indexFrag).commit();
                break;
            }
    
        }
    }
  • 相关阅读:
    idea主题更换pycharm/intellij
    随机生成n张扑克牌。
    JAVA生成6个1-8的随机数,要求无重复。
    一道简单 的循环
    linux虚拟机互访
    linux中grep命令
    vi和vim编辑器
    文件压缩打包以及备份
    文件内容查询
    目录相关操作
  • 原文地址:https://www.cnblogs.com/1426837364qqcom/p/5443292.html
Copyright © 2020-2023  润新知