package com.example.felipepr5;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
@SuppressLint("NewApi")
public class Main_fragment extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_fragment);
mTrocar
= (Button) findViewById
(R.
id.
buttonTrocar1);
mTrocar.setOnClickListener(this);
}
@Override
public void onClick
(View v
) {
Fragment newFragment = new Fragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Substitui quaisquer views do tipo fragment_containter com esse fragmento
// e adiciona uma transação ao back stack
transaction.add(R.id.myfragment, newFragment);
transaction.addToBackStack(null);
// Faz o commit da transação
transaction.commit();
}
}