package com.example.yyhan.test2;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;



public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    Button b1,b2,b3,b4,b5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(this);
        b2=(Button)findViewById(R.id.button2);
        b2.setOnClickListener(this);
        b3=(Button)findViewById(R.id.button3);
        b3.setOnClickListener(this);
        b4=(Button)findViewById(R.id.button4);
        b4.setOnClickListener(this);
        b5=(Button)findViewById(R.id.button5);
        b5.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button1:
                RightFragment1 Fragment1=new RightFragment1();
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                transaction.replace(R.id.right_layout,Fragment1);
                transaction.addToBackStack(null);
                transaction.commit();
                break;
            case R.id.button2:
                RightFragment2 Fragment2 = new RightFragment2();
                fragmentManager = getFragmentManager();
                transaction = fragmentManager.beginTransaction();
                transaction.replace(R.id.right_layout,Fragment2);
                transaction.addToBackStack(null);
                transaction.commit();
                break;
            case R.id.button3:
                RightFragment3 Fragment3 = new RightFragment3();
                fragmentManager = getFragmentManager();
                transaction = fragmentManager.beginTransaction();
                transaction.replace(R.id.right_layout,Fragment3);
                transaction.addToBackStack(null);
                transaction.commit();
                break;
            case R.id.button4:
                RightFragment4 Fragment4 = new RightFragment4();
                fragmentManager = getFragmentManager();
                transaction = fragmentManager.beginTransaction();
                transaction.replace(R.id.right_layout,Fragment4);
                transaction.addToBackStack(null);
                transaction.commit();
                break;
            case R.id.button5:
                RightFragment5 Fragment5 = new RightFragment5();
                fragmentManager = getFragmentManager();
                transaction = fragmentManager.beginTransaction();
                transaction.replace(R.id.right_layout,Fragment5);
                transaction.addToBackStack(null);
                transaction.commit();
                break;
            default:
                break;
        }
    }
}
