您的位置:首页 > 移动开发 > Android开发

android 智能电视 listview 顺序错乱

2015-03-30 18:07 253 查看
最近发现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,不是的话就重新填充

欢迎大家批评指证


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android listview 缓存