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.

10 Answers10

71

In your custom ArrayAdapter overide isEnabled method as following

@Override
public boolean isEnabled(int position) {
    return false;
}
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89
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.

Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
  • 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. – RenniePet Oct 01 '14 at 03:15
19

Add this to the xml

android:listSelector="@android:color/transparent"
DropAndTrap
  • 1,538
  • 16
  • 24
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

Ben
  • 3,832
  • 1
  • 29
  • 30
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);
Arvind Kanjariya
  • 2,089
  • 1
  • 18
  • 23
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
King of Masses
  • 18,405
  • 4
  • 60
  • 77
Basher51
  • 1,319
  • 1
  • 17
  • 28
2

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

shyam.y
  • 1,441
  • 1
  • 16
  • 17
2

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

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

Jayant Kapila
  • 67
  • 1
  • 5
1

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

CoDe
  • 11,056
  • 14
  • 90
  • 197
-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)

Nasz Njoka Sr.
  • 1,138
  • 16
  • 27