If I want to mark the second item I’m doing the following code:
This code is from my Adapter that extends ArrayAdapter :
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.channel_list, null);
}
MyContent o = items.get(position);
if (o != null) {
TextView tt = (TextView) convertView.findViewById(R.id.toptext);
TextView bt = (TextView) convertView.findViewById(R.id.bottomtext);
if (tt != null) {
tt.setText(o.Top());
}
if(bt != null){
bt.setText(o.Bottom());
}
if(position == 2) {
convertView.setBackgroundColor(R.color.selectem_color);
}
}
return convertView;
It will show the list view but mark every 9’th item after this item (the 11’th item 13’th and so on).
Does anyone know what’s the reason?
There are two cases in which the getView method can be called. If converView is null you have to create a new View. If it is not null an item that left the screen because of the user scrolling is recycled and returned to your method to be reused.
This object is an object that was shown in the list before. You have to check its state and set every property of it to the value you want it to have. You can’t act like the object is new you get marked and not marked objects back. Do something like this in your getview method.
In your code the else case of the if is missing.