什么是缓存图像的最佳方法?? android - 凌空

时间:2014-01-22 07:39:52

标签: android caching android-volley

我正在尝试用图像和Text填充列表视图。我使用volley框架从网络中获取数据。但问题是,当我向下滚动时,图像视图为空一秒钟,然后显示缓存图像..我希望缓存的图像始终显示在列表中。

代码:

public class SearchAdapterItem extends ArrayAdapter<SearchResultData>
{



Context context;
int layoutResourceId;
private ArrayList<SearchResultData> objects;
LayoutInflater inflater;
ImageLoader mImageLoader = new ImageLoader(ApplicationController.getInstance().getRequestQueue(), new BitmapLruCache());

public SearchAdapterItem(Context context, int layoutResourceId,  ArrayList <SearchResultData> objects)
{
    super(context, layoutResourceId, objects);

    this.context = context;
    this.objects =objects;
    this.layoutResourceId=layoutResourceId;

     inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);





}
private class ViewHolder {

    TextView txtTitle;
    TextView txtDesc;
    NetworkImageView imageicon;
    int position;
}







public View getView(int position, View convertView, ViewGroup parent)

{
    // assign the view we are converting to a local variable

    ViewHolder holder= new ViewHolder();

    // first check to see if the view is null. if so, we have to inflate it.
    // to inflate it basically means to render, or show, the view.


        if (convertView==null)
        {

            convertView = inflater.inflate(layoutResourceId,parent,false);
            holder.txtTitle=(TextView) convertView.findViewById(R.id.search_listingtitle);
            holder.imageicon= (NetworkImageView)        convertView.findViewById(R.id.search_listingimage);
            holder.position=position;

            convertView.setTag(holder);
        }

         else 
         {
             convertview.getTag();
          }




SearchResultData i = objects.get(position);

    if (i != null)
    {

        if (holder.txtTitle != null)
        {
            holder.txtTitle.setText(i.getListing_title());


            try {


                {

                  // holder.imageicon.setTag(i.getThumb_image());

                    holder.imageicon.setImageUrl(i.getThumb_image(), mImageLoader);



                }
                }
            catch (Exception e)
            {
                e.printStackTrace();
            }





        }



    }

    return convertView;

}

}

0 个答案:

没有答案