We found the onMenuItemSelected gets called instead. I would think it
is a bug but don't know for sure.

-Shon

On Apr 24, 9:21 am, Cristian Radu <cristi.en...@gmail.com> wrote:
> I have the same problem: a dialog with a list view on which I attach a
> context menu. When long-clicking the menu gets displayed, but clicking
> any option doesn't do anything - the onContextItemSelected method
> never gets executed.
>
> Any ideas? Is this a bug?
>
> On Mar 13, 10:29 pm, "Tim H." <timho...@gmail.com> wrote:
>
> > Setting the activity content view directly to aListView, the code
> > below works as expected. However, if you change the code (by
> > uncommenting the dialog lines, and commenting the setContentView
> > line), the context menu no longer works.
>
> > public class AndroidTest extends Activity {
> >         protected static final int ENTRY_ADD = Menu.FIRST;
> >         protected static final int ENTRY_REMOVE = Menu.FIRST + 1;
>
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setTheme(android.R.style.Theme_Dialog);
> >        ListViewlv = newListView(this);
> >         ArrayAdapter<CharSequence> adapter =
> > ArrayAdapter.createFromResource(
> >                 this, R.array.test,
> > android.R.layout.simple_list_item_1);
> >         lv.setAdapter(adapter);
> >         lv.setCacheColorHint(0);
> >         lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener
> > () {
> >                         public void onCreateContextMenu(ContextMenumenu, 
> > View v,
> >                                         ContextMenuInfo menuInfo) {
> >                                 menu.add(0, ENTRY_ADD, 1, "Add");
> >                                 menu.add(0, ENTRY_REMOVE , 2,"Remove");
> >                         }});
> >         //Dialog d = new Dialog(this);
> >         //d.setContentView(lv);
> >         //d.show();
> >         setContentView(lv);
> >     }
>
> >         @Override
> >         public boolean onContextItemSelected(MenuItemitem) {
> >                 AdapterView.AdapterContextMenuInfo info =
> > (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
> >                 Log.d("Test", "Selecteditem" + info.position);
> >                 switch(item.getItemId()) {
> >                 case ENTRY_ADD:
> >                         Log.d("Test", "Add was clicked");
> >                         break;
> >                 case ENTRY_REMOVE:
> >                         Log.d("Test", "Remove was clicked");
> >                         break;
> >                 default:
> >                         return super.onContextItemSelected(item);
> >                 }
> >                 return true;
> >         }
>
> > }
>
> > My workaround may be using an activity composed of only alistview,
> > with the dialog theme - which should work fine. But that seems like
> > some additional work for something that should work as described above.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to