在列表已更新并绘制后,如何为单个项目(条目)设置动画? [英] How can I animate one single item (entry) after the List is already updated and drawn?

查看:84
本文介绍了在列表已更新并绘制后,如何为单个项目(条目)设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个主ListView(使用this.getListView()检索)在从SQLite数据库正确填充的ListActivity中.单击其一项(条目)会使用startActivityForResult()调用另一项活动A2.当用户返回到ListActivity时,我想为那个SINGLE条目设置动画. (所以我想我需要重写onActivityResult()方法)

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)

一旦窗口获得焦点并且使用notifyDataSetChanged()更新列表后,如何为单个条目设置动画?

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

我设法使用

getListView().setAnimation(anim)

并且工作正常.但是,当我这样做时:

and worked fine. However, when I do:

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

什么都没发生.

编辑:这是我的onActivityResult代码

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

    }

}

推荐答案

在表中设置一个标志,然后在列表适配器上调用notifyDataSetChanged().使列表适配器中的getView()根据表中的标志确定要执行的操作(动画或不动画).我会发布一些示例代码,但我可以移动.

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.

编辑

onActivityResult()中,标记(带有一些值,布尔值,1/0等)要设置动画的数据集中的数据点.然后在适配器上调用notifyDataSetChanged().假设您有一个自定义列表适配器,请使您的getView()函数打开或关闭动画(或默认为关闭,并在给定标记的情况下翻转动画).

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
}

这篇关于在列表已更新并绘制后,如何为单个项目(条目)设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆