Google Groups

Re: onContextItemSelected Not Called When Including ABS


Jake Wharton Jan 11, 2012 8:29 AM
Posted in group: ActionBarSherlock
You'll have to specify the full package for one of them.

e.g.,

import android.support.v4.view.MenuItem

class Whatever extends FragmentActivity {
    public boolean onOptionsItemSelected(MenuItem item) {
        /* ... */
    }

    public boolean onConextItemSelected(android.view.MenuItem item) {
        /* ... */
    }
}

---
Jake Wharton
http://about.me/jakewharton


On Wed, Jan 11, 2012 at 11:25 AM, Rob Isakson <rob.i...@gmail.com> wrote:
Ahh that makes sense, but now onOptionsItemSelected is erroring, stating "Cannot override the final method from FragmentActivity", even though I am not @Override'ing that method.

Thanks,
Rob Isakson

PogramarProgramerProgramor. I write code.




On Wed, Jan 11, 2012 at 10:12 AM, Jake Wharton <jakew...@gmail.com> wrote:
You callback should explicitly be using android.view.MenuItem for context menu callbacks and not android.support.v4.view.MenuItem (which I'm going to assume is imported for normal options menu usage). If you add an @Override annotation to the callback you can ensure you're using the right type.

---
Jake Wharton
http://about.me/jakewharton



On Wed, Jan 11, 2012 at 11:02 AM, Rob Isakson <rob.i...@gmail.com> wrote:
So I've experienced this in 2 separate applications. After adding adding ActionBarSherlock to the project and adding an action bar to the activity, the onContextItemSelected never gets fired when an item is clicked from a long press context menu. I've tried a bunch of different things from my various googlings, but nothing seems to work. Any thoughts?

ListView list = (ListView) findViewById(R.id.scroll_list);
list.setAdapter(this.custom_adapter);
registerForContextMenu(list);
list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
menu.add(0, CONTEXT_EDIT, 0, "Edit");
menu.add(0, CONTEXT_DELETE, 1, "Delete");
}
}); 

public boolean onContextItemSelected(MenuItem item) {
Log.d("debug", "onContextItemSelected-item.getItemId():" + item.getItemId());
}