public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
//Fragment fragment = null;
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action buttons
switch(item.getItemId()) {
case R.id.action_release:
{
Toast.makeText(this, R.string.action_release, Toast.LENGTH_SHORT).show();
ReleaseFragment fragment2 = new ReleaseFragment();
Bundle args2 = new Bundle();
args2.putString("name", "发布");
fragment2.setArguments(args2);
FragmentTransaction transaction2 = getSupportFragmentManager().beginTransaction();
transaction2.replace(R.id.realtabcontent,fragment2);
//transaction2.addToBackStack(null);
transaction2.commit();
return true;
}
case R.id.action_search:
{
//Toast.makeText(this, R.string.action_search, Toast.LENGTH_SHORT).show();
SearchFragment fragment1 = new SearchFragment();
Bundle args1 = new Bundle();
args1.putString("name", "搜索");
fragment1.setArguments(args1);
FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction();
transaction1.replace(R.id.realtabcontent,fragment1);
//transaction1.addToBackStack(null);
transaction1.commit();
return true;
}
default:
return super.onOptionsItemSelected(item);
}
}
点击发布按钮会弹出toast提示,但是内容空白。点击搜索按钮会正确的显示内容和控件。