2013-03-22 70 views
1

我在我的操作欄sherlock中有一個列表。我想在用戶點擊該列表時獲得。 我不想知道用戶何時點擊一個項目,我已經知道(onNavigationItemSelected)。get on ListNavigation點擊操作欄

在我的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); 

我想檢測編程時,用戶點擊在我的操作欄列表導航。

回答

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; 
} 
+0

我tryiedit,不工作:( – 2013-03-25 06:56:33

+0

更新我的答案。請檢查一下。 – 2013-03-25 14:53:14