1

我的操作栏夏洛克有一个列表。我想在用户单击该列表时得到。我不想知道用户何时单击某个项目,我已经知道(onNavigationItemSelected)。

在我的 onCreate() 中:

// Set action bar
final ActionBar actionBar = getSherlockActivity().getSupportActionBar();
if (actionBar.getNavigationMode() != ActionBar.NAVIGATION_MODE_LIST) {
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
}
actionBar.setDisplayShowTitleEnabled(false);
mSelectionAdapter = new SelectionAdapter(getSherlockActivity().getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_dropdown_item, kinds);
actionBar.setListNavigationCallbacks(mSelectionAdapter, this);

当用户单击操作栏中的列表导航时,我想以编程方式进行检测。

4

1 回答 1

1

如果您只想在单击列表菜单等操作栏项时收到通知,则必须onMenuItemSelected按如下方式覆盖:

    @Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int itemId = item.getItemId();
//using logcat you may see what the list item id is?
 Log.i(TAG, "clicked actionbar itemid is: " + itemId );

//here you can setup a listener for every actionbar item selected
    switch (itemId) {
//android.R.id.list might not be the one you are searching pls check it out and compare it to logcat and put the appropriate itemId here
    case android.R.id.list:
//do whatever you want to do when list item is clicked
        break;
    }

    return true;
}
于 2013-03-22T11:42:35.300 回答