我的操作栏sherlock中有一个列表。我想在用户点击该列表时获得。 我不想知道用户何时点击某个项目,我已经知道(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);
我想在用户点击操作栏中的列表导航时以编程方式检测。
答案 0 :(得分: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;
}