我在从 SQLite 数据库正确填充的 ListActivity 中有这个主 ListView(使用 this.getListView()
检索)。单击其中一个项目(条目)会使用 startActivityForResult()
调用另一个 Activity A2。当用户返回 ListActivity 时,我想为该单个条目设置动画。 (所以我想我需要覆盖 onActivityResult()
方法)
如何在窗口获得焦点后以及使用 notifyDataSetChanged()
更新列表后为单个条目设置动画?
我设法为整个 ListView 使用动画
getListView().setAnimation(anim)
并且工作正常。但是,当我这样做时:
getListView().getChildAt(position).setAnimation(anim)
没有任何反应。
编辑:这是我的 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()
中,标记(带有一些值、 bool 值、1/0 等)数据集中您想要设置动画的数据点。然后在适配器上调用 notifyDataSetChanged()
。假设您有一个自定义列表适配器,让您的 getView()
函数打开或关闭动画(或者默认关闭并在给定标志的情况下将其打开)。
public View getView (int position, View convertView, ViewGroup parent){
// All the standard getView() stuff
if (listitem.shouldAnimate())
// animate
}
关于android - 在列表已经更新和绘制后,如何为单个项目(条目)设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14096044/