片段onOptionsItemSelected不会被调用 [英] Fragment onOptionsItemSelected not being called
本文介绍了片段onOptionsItemSelected不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经添加了名为份额为我的片段的操作栏菜单选项出现,但在选择时不被抓到
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);
}
试图捕捉到它在这两个片段与像
Trying to capture it in both the fragment and the fragment activity like
@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);
}
}
和我有setHasOptionsMenu(真正的);在OnCreate()
and i have setHasOptionsMenu(true); in the onCreate()
推荐答案
编辑的动作条福尔摩斯使用
Edit for actionbar sherlock use
我不得不使用
public boolean onMenuItemSelected(int featureId, MenuItem item) {
在主要活动捕捉菜单项
in the main activity to capture the menu item
这篇关于片段onOptionsItemSelected不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文