zoukankan      html  css  js  c++  java
  • 开启事务

    MainActivity。class:

    package com.bwei.day_11FragmentTransaction;
    
    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentTransaction;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class MainActivity extends FragmentActivity implements OnClickListener {
    
        private FragmentManager fm;
        private FragmentTransaction transaction;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Button weixin = (Button) findViewById(R.id.weixin);
    
            weixin.setOnClickListener(this);
            Button address_book = (Button) findViewById(R.id.address_book);
            address_book.setOnClickListener(this);
    
            fm = getSupportFragmentManager();
            
            transaction = fm.beginTransaction();
            transaction.add(R.id.frameLayout, new Weixin(), "weixin").addToBackStack(null).commit();
            
    
        }
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.weixin:
                transaction = fm.beginTransaction();
                transaction.add(R.id.frameLayout, new Weixin(), "weixin").addToBackStack(null).commit();
                break;
            case R.id.address_book:
                transaction = fm.beginTransaction();
                transaction.add(R.id.frameLayout, new AddressBook(), "addressBook").addToBackStack(null)
                        .commit();
    
                break;
    
            }
        }
    
    }

    AddressBook.class:

    /**
     * 
     */
    package com.bwei.day_11FragmentTransaction;
    
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    /**
     * @author WJL
     * 
     */
    public class AddressBook extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            return inflater.inflate(R.layout.address_book, null);
        }
    
    }

    Weixin.class:

    /**
     * 
     */
    package com.bwei.day_11FragmentTransaction;
    
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    /**
     * @author WJL
     * 
     */
    public class Weixin extends Fragment {
        /*
         * (non-Javadoc)
         * 
         * @see
         * android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
         * android.view.ViewGroup, android.os.Bundle)
         */
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            return inflater.inflate(R.layout.weixin, null);
        }
    
    }

    页面:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </FrameLayout>
    
        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="7" >
    
            <Button
                android:id="@+id/weixin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="微信" />
    
            <Button
                android:id="@+id/address_book"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="通讯录" />
        </LinearLayout>
    
    </LinearLayout>

    其中的fraglayout,可以替换任何布局,因为这就是事务所在的地方,就是来替换它的,其余两个页面,全靠自己定义,随着心情来的

  • 相关阅读:
    ES6:Iterator遍历器
    前端:对BFC的理解
    前端:性能优化之防抖与节流
    ES6新增数据类型Symbol
    ajax和fetch、aixos的区别
    我对js数据类型的理解和深浅(copy)的应用场景
    egg的基本使用
    前端:css3的过渡与动画的基础知识
    Java基础篇之类
    JAVA基础篇之Scanner
  • 原文地址:https://www.cnblogs.com/123p/p/5441844.html
Copyright © 2011-2022 走看看