How do I do this per selected list item.
I tried adding this to android:background
I was also facing your problem where the color change applies to the whole list.
But now its working for me now:
My main page containing the listview (noticed I did not apply the listselector here):
Instead applied the listselector to getView, its like tell that particular row (convertView) to use the listselector.xml in drawable foldable when its state changes, e.g. pressed, focused...:
@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;
}
And finally my listselector.xml:
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.