(不建议使用)片段onOptionsItemSelected没有被调用 [英] (Deprecated) Fragment onOptionsItemSelected not being called

查看:117
本文介绍了(不建议使用)片段onOptionsItemSelected没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是针对过时的夏洛克动作栏.现在应改为使用Android支持库

This question was for the deprecated sherlock action bar. Android support library should be used instead now

我为我的fragment添加了一个名为共享的操作栏菜单选项,该选项出现了,但未捕获选择事件

I have added an action bar menu option called share for my fragment which appears but the selection event is not being caught

我正在这样添加它

@Override
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
    MenuItem item = menu.add(0, 7,0, R.string.share);
    item.setIcon(R.drawable.social_share).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

试图同时在fragmentfragment activity中捕获它

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case 7:
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("text/plain");
            share.putExtra(Intent.EXTRA_TEXT, "I'm being sent!!");
            startActivity(Intent.createChooser(share, "Share Text"));
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

,我在onCreate()中有setHasOptionsMenu(true);.

推荐答案

为操作栏夏洛克使用而编辑

Edit for actionbar sherlock use

我不得不使用

public boolean onMenuItemSelected(int featureId, MenuItem item) {

在主要活动中捕获菜单项

in the main activity to capture the menu item

这篇关于(不建议使用)片段onOptionsItemSelected没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆