Reputation: 8978
I'm trying to implement a floating context menu in my application. I'm following an example provided by google: http://developer.android.com/guide/topics/ui/menus.html ,but stuck at the beginning with that piece of code:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
new AsyncTaskOne(this).execute();
getListView().setOnLongClickListener(new View.OnLongClickListener() {
// Called when the user long-clicks on someView
public boolean onLongClick(View view) {
Log.v("OnLongClick", "clicked"); // It doesn't log anything on a long click event.
if (mActionMode != null) {
return false;
}
// Start the CAB using the ActionMode.Callback defined above
mActionMode = actiV().startActionMode(mActionModeCallback);
view.setSelected(true);
return true;
}
});
}
I've put Log checking into onLongClick(View view)
method to find out if it's actually called. When I long-click some item from my ListView nothing happens (my Log.v
doesn't log anything). I'm wondering maybe the tutorial is missing something (some declaration in layout.xml)?
Upvotes: 1
Views: 1739
Reputation: 2371
You setting the long click listener to the whole listview, Did you really want to set an OnItemLongClick which would get the long click for an item in the list?
http://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html
Upvotes: 3