I need to change background color of a row in a listview when it's clicked by the finger. Example: I've got as listview with 5/6 rows; I need that with a single click on one row its background color becomes green (selected). W开发者_高级运维ith an other click on the selected row the background becames black again.
How can I do that?
Thank you
public View getView(final int position, View convertView,ViewGroup parent) {
ViewHolder holder;
if (convertView == null)
{
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
if(position == your selected row position)
{
convertView.setBackgroundColor(Color.YELLOW);
}
return convertView;
}
精彩评论