Disable Click Event on Android ListView Items
Asked Answered
P

10

28

I'm trying to disable multiple click events on listview, say after pressing first click some media gets played from webservice, while it gets played, other items need to be clickable==false , after media got played,other list items can be clickable.

What I'm trying is calling setClickable(true) and setClickable(false) on ListView Object.

Participle answered 19/4, 2013 at 7:9 Comment(2)
Set setClickable(false) on ListView during MediaPlayer is Playing and setClickable(true) when MediaPlayer is not playingTheresita
try setEnabled(false); for listviewKidnap
G
71

In your custom ArrayAdapter overide isEnabled method as following

@Override
public boolean isEnabled(int position) {
    return false;
}
Grandpapa answered 29/5, 2014 at 12:27 Comment(1)
Sexy, best solution :), used this on a GroupHeader in my list!Montpelier
F
36

Make your own subclass of ArrayAdapter that has AreAllItemsEnabled() return false, and define isEnabled(int position) to return false for a given item in your the ones you want to disable.

Filaria answered 19/4, 2013 at 7:23 Comment(1)
So far it is working for me to have some of the TextViews themselves marked disabled, and thus avoiding having to have an isEnabled(int position) method. But having the AreAllItemsEnabled() method present and returning false is necessary, thanks for that tip.Mignonne
I
19

Add this to the xml

android:listSelector="@android:color/transparent"
Internee answered 19/11, 2013 at 5:22 Comment(1)
Smart Solution : Only if you don't want the touch highlight to be seen. -- ThanksRochet
S
3

create Adapter for that list, and there override this method

public boolean isEnabled(int position);

then return false when you want to disable the click

Stercoricolous answered 15/5, 2014 at 12:14 Comment(0)
S
2

Manage Click event using flags.

While your media player is running set click to false by using this method.

setClickable(false);

When your media player is stop or not running or on complete set that flag to default value.

 setClickable(true);
Slambang answered 20/4, 2013 at 4:39 Comment(0)
D
2

before onCreate:

private long mLastClickTimeListViewItem = 0; 

To prevent multiple clicks on ListView Items

After onCreate inside the listener for listView,in my case the following:

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (SystemClock.elapsedRealtime() - mLastClickTimeListViewItem < 1000){
                return ;
            }
            mLastClickTimeListViewItem = SystemClock.elapsedRealtime();

            //Do your remaining code magic below...
            ....
            ....

         } // end of onItemClick method   
    }); // end of setOnItemClickListner
Demetri answered 12/7, 2014 at 16:20 Comment(0)
T
2

the above said answers didn't worked for me, so I used list.setEnabled(false) Its worked for me

Thermoluminescent answered 24/11, 2014 at 7:9 Comment(1)
Long lists become unscrollableShillong
A
2

listView.getChildAt(position).setEnabled(false);

listView.getChildAt(position).setClickable(false);

Atalie answered 21/1, 2021 at 19:15 Comment(0)
G
1

Or in simple way to un-register and register OnItemClickListener can be a better idea.

Gallaher answered 20/1, 2014 at 12:46 Comment(0)
A
-1

If what you want is just to diable items being clickable and show the appropriate selector color just use the line

android:listSelector="@android:color/transparent"

in you listview in the layout file(xml)

Affidavit answered 29/12, 2014 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.