Note that there are some explanatory texts on larger screens.

plurals
  1. POMy ListView items doesn't change color when setenabled false
    text
    copied!<p>I got this example from hear, but it doesn't work fine. My items were disabled but the color of my items (black) still the same.</p> <p>Thanks</p> <h2>The example</h2> <ul> <li>Create a ListView</li> <li>Enable filtering for the text view</li> <li>Make sure that the first item is disabled</li> <li>Filter the view so that the first item is not shown</li> </ul> <p>If you do this you can see that the new first item is disabled.</p> <p>So how do I best work around this?</p> <p>Below is the smallest possible sample code that demonstrates the problem, just filter for something other than the first three items.</p> <p><b>CustomListActivity.java</b></p> <pre><code>package com.example.bug; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; public class CustomListActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String items[] = new String[100]; for(int i = 0; i &lt; items.length; ++i) items[i] = "Item " + (i+1); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, items) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); view.setEnabled(isEnabled(position)); return view; } @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return position &gt;= 3; } }); getListView().setTextFilterEnabled(true); } } </code></pre> <p><b>AndroidManifest.xml</b></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.example.bug"&gt; &lt;uses-sdk android:minSdkVersion="7" /&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name="CustomListActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p><b>res/color/list_item_colors.xml</b></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_enabled="false" android:color="#777" /&gt; &lt;item android:color="#fff" /&gt; &lt;/selector&gt; </code></pre> <p><b>res/layout/list_item.xml</b></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10sp" android:textSize="16sp" android:textColor="@color/list_item_colors" /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload