Disable Click Event on Android ListView Items

前端 未结 10 1859
失恋的感觉
失恋的感觉 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: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
    

提交回复
热议问题