Disable click and gray out Listview Items [Android] -


some items in listview need disabled in specific situations. disabled means grayed out, , not clickable more. positions need disabled stored in arraylist named positions_to_disable.

i have done 1 part of task: have disabled clicking on these items overriding adapter's method boolean isenabled(int position);

 @override public boolean isenabled(int position) {          (int j = 0; j < fromwhereactivity.positions_to_disable.size(); j++) {             if (position == fromwhereactivity.positions_to_disable.get(j)) {                 return false;             }         }     return super.isenabled(position); } 

however, haven't found way grey them out. if try same thing overriding adapter's method view getview(int i, view view, viewgroup viewgroup), more items grayed out when scrolling, because method counts visible items instead of counting items in adapter. how can solve issue?

you need set background of list item statelistdrawable has different color disabled:

<?xml version="1.0" encoding="utf-8"?> <selector      xmlns:android="http://schemas.android.com/apk/res/android">      <item android:state_enabled="false"         android:drawable="@drawable/list_item_disabled"/>      <item         android:drawable="@drawable/list_item_normal"/>  </selector> 

see state list | android developers


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -