Changed the way we handle menu item clicks using MenuPopupHelper
Overriding onItemClick() doesn't allow us to get the MenuItem that was clicked when at least one menu item is hidden. This is because the position in the list of visible menu items is returned. But that value can't be used to retrieve the corresponding MenuItem (getItem() uses the position as index into the list of all menu items).
This commit is contained in:
parent
10e554e70e
commit
f22801e9d6
2 changed files with 14 additions and 22 deletions
|
@ -1985,10 +1985,9 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||
final MenuBuilder menu = new MenuBuilder(MessageList.this);
|
||||
getSupportMenuInflater().inflate(R.menu.message_list_item_context, menu);
|
||||
MenuPopup popup = new MenuPopup(MessageList.this, menu, v);
|
||||
popup.setOnMenuItemClickListener( new MenuPopup.OnMenuItemClickListener() {
|
||||
popup.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(int itemId){
|
||||
MenuItem item = menu.getItem(itemId);
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
final List<MessageInfoHolder> selection = getSelectionFromMessage(message);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.reply: {
|
||||
|
@ -2045,7 +2044,9 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||
}
|
||||
}
|
||||
|
||||
} } );
|
||||
return true;
|
||||
}
|
||||
});
|
||||
popup.show();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,33 +1,24 @@
|
|||
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import com.actionbarsherlock.internal.view.menu.MenuBuilder;
|
||||
import com.actionbarsherlock.internal.view.menu.MenuPopupHelper;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
public class MenuPopup extends MenuPopupHelper {
|
||||
|
||||
OnMenuItemClickListener onMenuItemClickListener;
|
||||
private MenuBuilder mMenu;
|
||||
|
||||
|
||||
public MenuPopup(Context context, MenuBuilder menu, View anchorView) {
|
||||
super(context, menu, anchorView);
|
||||
mMenu = menu;
|
||||
}
|
||||
|
||||
public void setOnMenuItemClickListener(
|
||||
OnMenuItemClickListener onMenuItemClickListener) {
|
||||
this.onMenuItemClickListener = onMenuItemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
super.onItemClick(parent, view, position, id);
|
||||
if (onMenuItemClickListener != null)
|
||||
onMenuItemClickListener.onMenuItemClick(position);
|
||||
}
|
||||
|
||||
public interface OnMenuItemClickListener{
|
||||
public void onMenuItemClick(int itemID);
|
||||
public void setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener listener) {
|
||||
for (int i = 0, end = mMenu.size(); i < end; i++) {
|
||||
mMenu.getItem(i).setOnMenuItemClickListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue