Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate newly added items in ListView

How can I animate newly added items in ListView?

I have a adapter and when I add new items in my list I say adapter.notifyDataSetChanged(); the items are added, everything works perfectly, but my problem is I want newly added element to have some animation.

like image 264
Lukap Avatar asked Jun 07 '11 11:06

Lukap


1 Answers

Animate each added element in the getView() method of your Custom Adapter.

public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;

    if (v == null) {
        LayoutInflater vi = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.simple_list_item_1, null);
    }

    ListData o = list.get(position);
    TextView tt = (TextView) v.findViewById(R.id.toptext);

    tt.setText(o.content);

    Log.d("ListTest", "Position : "+position);
    if(flag == false) {
        Animation animation = AnimationUtils
                .loadAnimation(getActivity(), R.anim.slide_top_to_bottom);
        v.startAnimation(animation);
    }
    return v;
}

And thereby achieve the Animation.

like image 71
ASH Avatar answered Oct 14 '22 19:10

ASH