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>
Comments
Post a Comment