我有这个主要的ListView(检索使用this.getListView()
)在ListActivity正确填充从SQLite数据库。点击其中一个项目(条目)使用startActivityForResult()
调用另一个活动A2。当用户回到ListActivity时,我想动画那个单条目。(所以我想我需要覆盖onActivityResult()
方法)
一旦窗口获得焦点,并且使用notifyDataSetChanged()
更新列表后,我如何使单个条目动画?
我用
把整个ListView做成动画getListView().setAnimation(anim)
并且工作正常。但是,当我这样做时:
getListView().getChildAt(position).setAnimation(anim)
什么也不会发生。
EDIT:这是我的onActivityResult代码
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()
在你的列表适配器决定做什么(动画或不)基于你的表中的标志。我想张贴一些示例代码,但我是移动的。
在你的onActivityResult()
中,标志(带有一些值,布尔值,1/0等)你想要动画的数据集中的数据点。然后调用适配器上的notifyDataSetChanged()
。假设您有一个自定义列表适配器,让您的getView()
函数打开或关闭动画(或者默认为关闭并打开给定的标志)。
public View getView (int position, View convertView, ViewGroup parent){
// All the standard getView() stuff
if (listitem.shouldAnimate())
// animate
}