android 智能电视 listview 顺序错乱

来源:互联网 发布:奔驰s600电脑编程 编辑:程序博客网 时间:2024/05/20 18:46

最近发现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
原创粉丝点击