I have a listview , in which I am showing file and folder lists. I am using my getView method as
static class ViewHolder {
protected TextView text1;
protected TextView text2;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, parent, false);
viewHolder = new ViewHolder();
viewHolder.text1 = (TextView) convertView.findViewById(R.id.text1);
viewHolder.text2 = (TextView) convertView.findViewById(R.id.text2);
convertView.setTag(viewHolder);
}
else{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.text1.setText(itemsArrayList.get(position).getFileName());
viewHolder.text2.setText(itemsArrayList.get(position).getSize());
<if( itemsArrayList.get(position).isHidden() ) {
convertView.setBackgroundColor(context.getResources().getColor(R.color.hiddenColor));
}
return convertView;
}
If file/folder is hidden , I am changing background color of list item as hiddenColor,
(default background color is in XML)
But on scrolling it sets almost all list item background color as hiddencolor.
I know this is due to listview recycling, but no idea how to resolve it.
You have to set the not hidden color too, because if the view is reused you will get the hiddenColor if it was set before to that convert view.
if( itemsArrayList.get(position).isHidden() ) {
convertView.setBackgroundColor(context.getResources().getColor(R.color.hiddenColor));
} else {
**convertView.setBackgroundColor(Put your other color here)**
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With