Question

I have a ListView and want to get the long-click events on the ListView itself, not on the individual items in the ListView. I believe it should be as straight forward as just called ListView.setOnLongClickListener(View.OnLongClickListener). However, for me, it seems to do nothing at all. I'm just wondering if anyone else has the same issue with all ListViews or it just me and my implementation of the ListView made this not work.

I referred to this answer and tried using ListView.setLongClickable(true) but it still didn't work.

Was it helpful?

Solution

It might be easier to define a separate TextView in the parent layout, with id attribute to be android:id="@+id/android:empty" which would be displayed if there are no elements in the ListView, saying something like "--List is empty--", and that being long-clickable. You can easily manipulate the Click for the respective TextView.

In cases where the ListView ought to be long clickable, you can leave a small gap on the parent view, and set the parent view as Long clickable, rather than the ListView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top