I made a custom list adapter extending the Base adapter. Each item in the list has an imagebutton, 2 textviews and a button. I tried to add the context menu to the list so as to display some options for an item in the list.
registerForContextMenu(getListView());
I used a MenuInflater object to inflate the context menu xml file. But on clicking the items in the list nothing shows up or the usual highlighting of the item of list on click isn't shown. Is it that the context menu doesn't work for custom list views? Any help would be much appreciated.
Regards, Primal
Make sure child items of ListView must be Long Clickeable.
It can be done in the xml layout file, for example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:longClickable="true">
<!-- Child elements -->
</LinearLayout>
Or it can be done in java code:
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
CustomView customView = new CustomView();
customView.setLongClickeable(true);
}
I hope it helps.
It should work for custom list adapters. The only thing that comes to mind is that registerForContextMenu() needs to be called after setListAdapter() (if you're using ListActivity).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With