Disable Click Event on Android ListView Items

前端 未结 10 1860
失恋的感觉
失恋的感觉 2021-02-05 04:13

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

相关标签:
10条回答
  • 2021-02-05 04:48

    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.

    0 讨论(0)
  • 2021-02-05 04:50

    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
    
    0 讨论(0)
  • 2021-02-05 04:54

    Add this to the xml

    android:listSelector="@android:color/transparent"
    
    0 讨论(0)
  • 2021-02-05 04:56

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

    0 讨论(0)
提交回复
热议问题