public class MainActivity extends Activity {
Fragment fr;
FragmentManager fm;
Button btn1,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
btn1=(Button)findViewById(R.id.button1);
btn2=(Button)findViewById(R.id.button2);
fm = getFragmentManager();
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
fr = new frag22();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment, fr);
ft.commit();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId() == android.R.id.home) { //app icon in action bar clicked; go back
//do something
Toast.makeText(getApplicationContext(), "set click", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}