The context menu is not popping up on the long click on the list items in the list view. I've extended the base adapter and used a view holder to implement the custom list with textviews and an imagebutton.
adapter = new MyClickableListAdapter(this, R.layout.timeline, mObjectList);
list.setAdapter(adapter);
registerForContextMenu(list);
Implementation of onCreateContextMenu
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
Log.d(TAG, "Entering Context Menu");
menu.setHeaderTitle("Context Menu");
menu.add(Menu.NONE, DELETE_ID, Menu.NONE, "Delete")
.setIcon(R.drawable.icon);
}
The XML for listview is here
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
I've been trying this for many days. I think its impossible to register Context-menu for a custom list view like this. Correct me if I am wrong (possibly with sample code).
Now I am thinking of a adding a button to the list item and it displays a menu on clicking it. Is it possible with some other way than using Dialogs?
Any help would be much appreciated..
Such problem arises in list view when it has focusable items like checkbox, radioButton,etc. To solve this in the layout for the list item for the focusable items include :
Why didn't you use
ListActivity
?In my ListActivity I have:
Use OnItemLongClickListener (via the set~) method of the ListView.