在listview中加载图像的线程

时间:2013-01-02 06:00:40

标签: android listview

我正在使用线程在我的BaseAdapter类的getview()中加载图像。但是图像没有正确加载..当我滚动列表视图图像正在改变时..某些位置的图像即将来临...帮助我解决这个问题。

这是我的getview代码:

public View getView(int position, View convertView, ViewGroup parent) 
    {
        // TODO Auto-generated method stub      

//       View listView = convertView;
        Position=position;
         ViewHolder holder;

         Thread thread = new Thread()
         {
             public void run() 
             {
                  bitmap=   DownloadImage(
                         kickerimage[Position] );       

             }
         };
         thread.start();
//  Bitmap bitmap=  DownloadImage(
//               kickerimage[position] );       

         if (convertView   == null) 
            {
                //this should only ever run if you do not get a view back            
             LayoutInflater  inflater = (LayoutInflater) contxt
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             convertView  = inflater.inflate(R.layout.homelistrow, null); 

             holder = new ViewHolder();

             holder.image = (ImageView) convertView
                        .findViewById(R.id.icon);


             holder.text = (TextView) convertView
                        .findViewById(R.id.name_label);
             convertView.setTag(holder);            
            }

         else
                    { 
                        holder = (ViewHolder) convertView.getTag();         
                     }
//       





         holder.image.setImageBitmap(bitmap);
////         items=itemsarray[position];
         holder.text.setText(itemsarray[position]);

return convertview
}

1 个答案:

答案 0 :(得分:1)

ListView中图片的延迟加载是您正在寻找的,下面的链接可能会帮助您。另外尝试在Android中搜索谷歌延迟加载图片,可能会有很多结果可能会帮助你。

  1. Android, how to lazy load images from url and persistently cache them in gallery widget?

  2. LazyList