Disable Click Event on Android ListView Items

风流意气都作罢 提交于 2019-12-31 20:05:20

问题


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.


回答1:


In your custom ArrayAdapter overide isEnabled method as following

@Override
public boolean isEnabled(int position) {
    return false;
}



回答2:


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.




回答3:


Add this to the xml

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



回答4:


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




回答5:


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);



回答6:


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




回答7:


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



回答8:


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




回答9:


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)



来源:https://stackoverflow.com/questions/16099113/disable-click-event-on-android-listview-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!