user4256388
user4256388

Reputation:

ListView - animation when adding new row

I'm just trying to create animation for "add" method in listview. This works rly great, but animation is also triggered by removing item from the listview.

So

insert to index 0 -> "item 1" -> animation
insert to index 0 -> "item 2" -> animation
insert to index 0 -> "item 3" -> animation 

result

item 3 
item 2
item 1

and now I want to remove "item 1" for example... and animation is of course triggered on index 0 (item 3 -> starting animation)

How do I know that this is a removing method?

private static void blink(final View v) 
{
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(300);
    animation.setStartOffset(20);
    animation.setRepeatMode(Animation.REVERSE);
    animation.setRepeatCount(Animation.INFINITE);
    v.setAnimation(animation);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            v.setAnimation(null);
        }
    }).start();
}

Adapter

@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent)
{
    LayoutInflater inflater = LayoutInflater.from(getContext());
    View view = inflater.inflate(R.layout.alert_custom_row, parent, false);

    if(position == 0) // HERE some like isNewRow()?
        blink(view);

    return view;
}

Activity

adapter.insert("item", 0);
adapter.notifyDataSetChanged();

Thanks a lot for helping me.

Upvotes: 0

Views: 166

Answers (1)

Bronz
Bronz

Reputation: 217

Without another "list" object with the number of items to compare the adapter's getCount () I would not know exactly how to figure out whether you're adding or deleting it.

Upvotes: 1

Related Questions