它会在UI上为错误的行设置动画.在某些时候,视图持有正确的数据,但随后被回收.我通过logcat证实了这一点.
有什么方法可以解决这个问题吗?
编辑:
public ExpensCursorAdapter(Context context,Cursor c,boolean autoRequery,copyOnWriteArraySet<String> fadeAnimateTags) { super(context,c,autoRequery); this.mFadeAnimTags = fadeAnimateTags;}@OverrIDepublic boolean hasStableIDs() { return true;}@OverrIDepublic voID bindVIEw(VIEw vIEw,Context context,Cursor cursor) { setup(vIEw,context,cursor);}private voID setup(VIEw vIEw,Cursor cursor) { final String ID = cursor.getString(4); if (LOCAL_LOGV) Log.v(TAG,String.format("Create item for %s. Received vIEw: %s",ID,vIEw.toString())); vIEw.setTag(ID); final TextVIEw dateText = (TextVIEw) vIEw.findVIEwByID(R.ID.date); final TextVIEw timeText = (TextVIEw) vIEw.findVIEwByID(R.ID.time); final TextVIEw Title = (TextVIEw) vIEw.findVIEwByID(R.ID.Title); final TextVIEw amount = (TextVIEw) vIEw.findVIEwByID(R.ID.amount); final Date date = new Date(cursor.getLong(0)); Title.setText(cursor.getString(1)); dateText.setText(dFormat.format(date)); timeText.setText(tFormat.format(date)); amount.setText(String.format("%d Ft",cursor.getInt(2))); if (cursor.getInt(3) == 1) { timeText.setTextcolor(color.LTGRAY); Title.setTextcolor(color.LTGRAY); dateText.setTextcolor(color.LTGRAY); amount.setTextcolor(color.LTGRAY); } else { timeText.setTextcolor(color.BLACK); Title.setTextcolor(color.BLACK); dateText.setTextcolor(color.BLACK); amount.setTextcolor(color.BLACK); } if (mFadeAnimTags.contains(ID)) { vIEw.setAnimation(AnimationUtils.loadAnimation(context,R.anim.fade)); mFadeAnimTags.remove(ID); }}@OverrIDepublic VIEw newVIEw(Context context,Cursor cursor,VIEwGroup parent) { final LayoutInflater inflater = LayoutInflater.from(context); VIEw vIEw = inflater.inflate(R.layout.expense_List_item,parent,false); setup(vIEw,cursor); return vIEw;}解决方法 在自定义适配器的getVIEw方法中为每个添加的元素设置动画.
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;}
从而实现动画.
总结以上是内存溢出为你收集整理的android – ListView中的动画列表项全部内容,希望文章能够帮你解决android – ListView中的动画列表项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)