Artur G. Artur G. - 6 months ago 37
Android Question

Too much blinking rows in ListView

I have

listView
with its own adapter. This is the fragment
getView
method from the adapter code:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
//this code works properly
switch(dane_status.get(position)) {
case "zgłoszone": mojView_holder.tekst_data.setTextColor(convertView.getContext().getResources().getColor(R.color.zamZgloszColor)); break;
default: mojView_holder.tekst_data.setTextColor(0xFFC0C0C0); //silver
}
//this code not working properly
if (dane_status.get(position).equals("zgłoszone")) {
Animation anim = new AlphaAnimation(0.2f, 1.0f);
anim.setDuration(200); //You can manage the blinking time with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
convertView.startAnimation(anim);
}
return convertView;
}


I'm using
Animation
to only blink the rows where the status is 'zgłoszone'. These rows really are blinking, but on my list the first row is blinking and every first row on each next "screen" -
ListView
have 11 rows visible and blinking is row 1, 13, 25, 37...

It's important that coloring date (switch instruction) works OK. I only have problems with
Animation
.

What am I doing wrong?

Answer

It's possible that the animation is continuing when you recycle the views. Try clearing any current animations using View.clearAnimation().

if (date_status.get(position).equals("zgłoszone")) {
    ...
} else {
    convertView.clearAnimation();
}