Android-ActionSherlock导航栏按钮不';不要调用相应的操作

Android-ActionSherlock导航栏按钮不';不要调用相应的操作,android,actionbarsherlock,android-actionbar,Android,Actionbarsherlock,Android Actionbar,我已经能够在我的actionbar上放置共享小部件和ListNavigation。但是,当我单击它们时,“共享”按钮不会为我提供共享选项,列表导航也不会将我带到我选择的列表项 以下是我必须设置的代码: public class MainActivity extends SherlockActivity implements ActionBar.OnNavigationListener { Dialog dialog; private TextView mSelected;

我已经能够在我的actionbar上放置共享小部件和ListNavigation。但是,当我单击它们时,“共享”按钮不会为我提供共享选项,列表导航也不会将我带到我选择的列表项

以下是我必须设置的代码:

public class MainActivity extends SherlockActivity implements ActionBar.OnNavigationListener
{
    Dialog dialog;

    private TextView mSelected;
    private String[] mLocations;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTheme(R.style.Theme_Sherlock_Light);

        //setContentView(R.layout.list_navigation);
        mSelected = (TextView)findViewById(R.id.text);

        mLocations = getResources().getStringArray(R.array.locations);


        Context context = getSupportActionBar().getThemedContext();
        ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(
                context, R.array.locations, R.layout.sherlock_spinner_item);
        list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        getSupportActionBar().setListNavigationCallbacks(list, this);        

and here is my menu inflater and other relevant methods:

    public boolean onCreateOptionsMenu(Menu menu)
    {       
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }

    private Intent createShareIntent() 
    {   
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain"); //shareIntent.setType("image/*");

        shareIntent.putExtra(Intent.EXTRA_TEXT,"Mobile apps to plan and start your busienss, covering business ideas, business planning, marketing and fundraising.");
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Check out http://www.myurl.com");

        return shareIntent;
    }    
这是我的主菜单

<menu xmlns:android="http://schemas.android.com/apk/res/android">  

<item android:id="@+id/menu_item_share"         
android:showAsAction="ifRoom"         
android:title="Share"         
android:actionProviderClass="android.widget.ActionProvider" />  

<item
android:id="@+id/menuSort"
android:showAsAction="ifRoom"
android:actionLayout="@layout/action_sort"  />

</menu>
下面是应用程序上的屏幕元素如何变灰的屏幕截图:

如果我在代码中放入调试语句,onNavigationItemSelected()方法似乎会在循环中不断被调用,大约每分钟调用100次

谢谢!
-Alex

您似乎已经注释掉了实际连接导航侦听器的行:

// getSupportActionBar().setListNavigationCallbacks(list, this);
我看不到选项ItemSelected(MenuItem),当按下操作栏按钮时会调用它


另外,不确定您是否忘记了导航项Selected上的
@Override
注释和
onCreateOptions菜单上的
,但它没有显示。

我之所以评论换行,是因为它会导致奇怪的应用程序行为。当那条线重新插进去时,整个屏幕就会被灰色覆盖。因此,应用程序显示为灰色。你知道为什么会发生这种情况吗?是的,我的@averrides在那里-我只是没有复制它们。我认为OnOptions ItemSelected(MenuItem)是不需要的,因为onNavigationItemSelected()方法可以告诉你选择了什么ListNavigation项。或者我有什么地方错了?@Genadinik如果未设置
setListNavigationCallbacks
,就不会有回调。您的适配器没有“挂接”任何东西
onNavigationItemSelected
仅从微调器调用。您必须对菜单项使用
onOptions ItemSelected
。在“应用程序显示为全灰色”问题上,我需要查看完整的代码来确定该问题,但这不是我见过/听说过的。请随意链接到粘贴箱,我来看看。
[2013-06-27 08:43:57 - actionbarsherlock] 'default' is not a best match for any device/locale combination.
[2013-06-27 08:43:57 - actionbarsherlock] Displaying it with ', , Locale Language ___Region __, sw320dp, w320dp, h533dp, Normal Screen, Long screen aspect ratio, Portrait Orientation, Normal, Day time, High Density, Finger-based touchscreen, Soft keyboard, No keyboard, Hidden navigation, Trackball navigation, Screen resolution 800x480, API Level 15' which is compatible, but will actually be displayed with another more specific version of the layout.
// getSupportActionBar().setListNavigationCallbacks(list, this);