I have a ListView
with custom adapter and I want to change the background color of an item. I used this code:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final Holder holder = new Holder();
final View rowView;
rowView = inflater.inflate(R.layout.program_list, null);
holder.tv = (TextView) rowView.findViewById(R.id.textView1);
holder.img = (ImageView) rowView.findViewById(R.id.imageView1);
holder.tv.setText(result[position]);
holder.img.setImageResource(imageId[position]);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (position != 0) {
rowView.setBackgroundColor(Color.rgb(70, 190, 200));
}
}
});
return rowView;
}
It is working fine, but my question is - how can I change the next item color within the onclick
function with knowing the last item will not get pressed(causing out of bounds error)? (If I press the item at position 4, then change the background color of position 5).
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// ?
}
});
Thanks :)