android 智能电视 listview 顺序错乱

在填充ListView时遇到顺序错误的问题。通过检查convertView的Tag与当前位置是否匹配来解决,匹配则使用缓存的View,不匹配则重新布局并设置Tag,确保每个item的正确显示。
摘要由CSDN通过智能技术生成

最近发现listview 填充好之后总是顺序错了


为了解决这个问题参考网上的思路


解决办法

 ImageView imageView = null;
  TextView textView2_appname = null;
  
  int index;
  try {
   index = (Integer) convertView.getTag();
  } catch (Exception e) {
   index =-1;
   e.printStackTrace();
  }
  if (index != position) {
   convertView = layoutInflater.inflate(R.layout.addapk_item, null);
   imageView = (ImageView) convertView.findViewById(R.id.iv_icon);
   textView2_appname = (TextView) convertView
     .findViewById(R.id.tv_appname);
   if (Applist.size() == 0) {
    textView2_appname.setText("没有对应类型APP");
   } else {
    imageView.setBackgroundDrawable((Drawable) Applist
      .get(position).get("icon"));
    textView2_appname.setText((String) Applist.get(position).get(
      "appname"));
    convertView.setTag(position);
   }
  }else {
   time = time+1;
  }
  

  return convertView;

使用settag()解决这个问题,每次去获取tag是不是和post对应,对应的话就 返回listview缓存中的view,不是的话就重新填充



欢迎大家批评指证


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值