1

I have this main ListView (retrieved using this.getListView()) in a ListActivity properly populated from a SQLite database. A click on one of its items (entries) calls another activity A2 using startActivityForResult(). I would like to animate that SINGLE entry WHEN the user gets back to the ListActivity. (So I suppose I need to override the onActivityResult() method)

How can I animate a single entry once the window gained focus and after the list is updated using notifyDataSetChanged()?

I managed to animate the whole ListView using

getListView().setAnimation(anim)

and worked fine. However, when I do:

getListView().getChildAt(position).setAnimation(anim)

nothing happens.

EDIT: Here's my onActivityResult code

protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {

    super.onActivityResult(requestCode, resultCode, intent);

    if(resultCode==RESULT_OK && requestCode==SOME_REQUEST_CODE){

        Animation anim = new AlphaAnimation(1.0f,0.0f);  
        anim.setFillAfter(true);  
        anim.setDuration(400); 
        anim.setRepeatMode(Animation.REVERSE);
        anim.setRepeatCount(7);
        // Just for testing, I chose the first item of the ListView (position=0)
        tr_adapter.getView(0, getListView().getChildAt(0), getListView()).setAnimation(anim);

        tr_adapter.notifyDataSetChanged(); //Nothing happens

    }

}
Maruen
  • 11
  • 3

1 Answers1

1

Set a flag in your table and call notifyDataSetChanged() on your list adapter. Have getView() in your list adapter determine what to do (animate or not) based on the flag in your table. I'd post some sample code but I'm mobile.

EDIT


In your onActivityResult(), flag (with some value, boolean, 1/0, etc) the data point in your data set that you'd like to animate. Then call notifyDataSetChanged() on the adapter. Assuming you have a custom list adapter, have your getView() function flip the animation on or off (or default to off and flip it on given the flag).

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

    // All the standard getView() stuff

    if (listitem.shouldAnimate())
        // animate
}
jsimon
  • 577
  • 6
  • 17
  • Thanks for your reply Jsimon, but I didn't really understand your method. It would be great if you could leave an example. – Maruen Dec 31 '12 at 09:18
  • 1
    hint: "Assuming you have a custom list adapter ... ". If you don't have a custom list adapter then you will need to create one so that you can add your animation code in the getView(...) method as described above. Look at this tutorial http://www.vogella.com/articles/AndroidListView/article.html – Akos Cz Jan 02 '13 at 01:56
  • Thanks Akos Cz ! (Sorry for replying so late) – Maruen Jan 22 '13 at 08:39
  • Sorry jsimon I didn't notice your EDIT, I already did as you suggested, thanks ! – Maruen Jan 22 '13 at 08:42