// In first fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag_1, null);
Button button1 = (Button) view.findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
MainActivity.fragmentTransaction = MainActivity.fragmentManager.beginTransaction();
Fragment2 fragment2 = new Fragment2();
MainActivity.fragmentTransaction.replace(R.id.fragment_container, fragment2);
MainActivity.fragmentTransaction.addToBackStack(fragment2.toString());
MainActivity.fragmentTransaction.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
return view;
}