package com.example.mobapp_13;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.widget.ToggleButton;

public class SecondActivity extends FragmentActivity {

	Fragment1 firstFragment;
	Fragment2 secondFragment;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_second);
		
		if (savedInstanceState != null) {
            return;
        }
		
        // Create an instance of ExampleFragment
        firstFragment = new Fragment1();
        secondFragment = new Fragment2();
        
        
        // In case this activity was started with special instructions from an Intent,
        // pass the Intent's extras to the fragment as arguments
        //firstFragment.setArguments(getIntent().getExtras());
        
        // Add the fragment to the 'fragment_container' FrameLayout
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fragment_container, firstFragment).commit();
		
	}
	public void switchfragment(View view)
	{
		ToggleButton tb = (ToggleButton)findViewById(R.id.toggleButton1);
		
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

		// Replace whatever is in the fragment_container view with this fragment,
		// and add the transaction to the back stack so the user can navigate back
		
		if (tb.isChecked())
		{
			transaction.replace(R.id.fragment_container, secondFragment);
		}
		else
		{
			transaction.replace(R.id.fragment_container, firstFragment);
		}
		transaction.addToBackStack(null);
		// Commit the transaction
		transaction.commit();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.second, menu);
		return true;
	}

}
