package com.bgstation0.android.sample.fragmenttransaction_;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        if (savedInstanceState == null){

        	// ButtonÌú».
            Button button1 = (Button)findViewById(R.id.button1);	// button1ðæ¾.
            button1.setOnClickListener(new OnClickListener() {	// Xi[ðZbg.
    			
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				// Fragment2ð\¦µ, Fragment1ðñ\¦É·é.
    				FragmentManager fragmentManager = getFragmentManager();	// fragmentManagerÌæ¾.
    		        Fragment f1 = fragmentManager.findFragmentById(R.id.framelayout1);	// f1ðæ¾.
    		        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();	// fragmentTransactionÌæ¾.
    		        fragmentTransaction.remove(f1);	// f1ðí.
    		        fragmentTransaction.commit();	// mè.      
    			}
    			
    		});
            
            // tOgÌÇÁ.
            FragmentManager fragmentManager = getFragmentManager();	// fragmentManagerÌæ¾.
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();	// fragmentTransactionÌæ¾.
            Fragment1 fragment1 = new Fragment1();	// fragment1Ì¶¬.
            fragmentTransaction.add(R.id.framelayout1, fragment1);	// fragment1ðÇÁ.
            fragmentTransaction.commit();	// mè.
            
        }
        
    }
    
}
