kevinjqy 2014-11-07 03:09
浏览 1477

actionbar里添加发布和搜索按钮,但点击发布按钮无法跳转到相关fragment

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提示,但是内容空白。点击搜索按钮会正确的显示内容和控件。

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题