Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was also facing your problem where the color change applies to the whole list. </p> <p>But now its working for me now:</p> <p>My main page containing the listview (noticed I did not apply the listselector here): </p> <pre><code> &lt;ListView android:id="@+id/controlList" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; </code></pre> <p>Instead applied the listselector to getView, its like tell <strong>that particular row (convertView)</strong> to use the listselector.xml in drawable foldable when its state changes, e.g. pressed, focused...:</p> <pre><code>@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if(convertView == null){ LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); convertView = li.inflate(R.layout.control_list, null); viewHolder = new ViewHolder(); viewHolder.topText = (TextView) convertView.findViewById(R.id.toptext); viewHolder.bottomText = (TextView) convertView.findViewById(R.id.bottomtext); convertView.setTag(viewHolder); } else{ viewHolder = (ViewHolder) convertView.getTag(); } //each convertView will be assigned the listselector convertView.setBackgroundResource(R.drawable.listselector); viewHolder.topText.setText(testSchemes[position]); //viewHolder.vText.setText(testDetails[position]); return convertView; } </code></pre> <p>And finally my listselector.xml:</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_pressed="false" android:state_selected="false" android:drawable="@color/lightgreen" /&gt; &lt;!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. --&gt; &lt;item android:state_pressed="true" android:drawable="@color/darkgreen" /&gt; &lt;item android:state_selected="true" android:state_pressed="false" android:drawable="@color/orange" /&gt; &lt;/selector&gt; </code></pre> <p>This is what the above code does: All entries when first loaded are lightgreen. Scrolling up and down using cursor highlights the selected entry orange. Pressing a row turns it to darkgreen.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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