I have a ListView, and for the first time I show it. I want to disable some of its elements.
For this, I did this textorange_selected.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="false" android:color="@color/medium_gray" /> <item android:state_selected="true" android:color="@android:color/white" /> <item android:state_focused="true" android:color="@android:color/white" /> <item android:state_pressed="true" android:color="@android:color/white" /> <item android:color="@color/lighter_orange" /> </selector>
and I use it in the line layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="20dp" android:gravity="left|center" android:layout_width="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp" android:background="@color/list_bg"> <ImageView android:id="@+id/avatar" android:layout_width="48dp" android:layout_height="48dp" android:layout_marginTop="10dp" android:layout_alignParentLeft="true" /> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="48dp" android:layout_toRightOf="@+id/avatar" android:layout_marginLeft="10dp" android:layout_marginTop="5dp"> <TextView android:id="@+id/listitem1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="2dp" android:textColor="@drawable/textblack_selected" android:textSize="18dp" android:textStyle="bold" /> <TextView android:id="@+id/listitem2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:textColor="@drawable/textorange_selected" /> </LinearLayout> <ImageView android:id="@+id/arrowImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:layout_alignParentRight="true" android:src="@drawable/arrow_selector" /> </RelativeLayout>
The problem is that it never goes into android:state_enabled="false" (this should be the moment the item is disabled, and I set the text color to gray).
To disable elements, I use this code in my adapter:
@Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return position < 1; }
Where is my mistake?
source share