Skip to content Skip to sidebar Skip to footer

Loading Images To Custom Listview - How To Gradually Load?

I have a custom Listview - which contains an imageView, text and a checkbox. I am loading images from dropbox (taking the thumnails or else getting the shared URL to the image) and

Solution 1:

For this you can use Universal Image loader jar universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar

Then adapter is like this

publicclassLinkAdapterextendsArrayAdapter<MediaModel>{

    ArrayList<MediaModel> medias;
    Activity context;
    ImageLoader imageLoader;
    DisplayImageOptions options;

    publicLinkAdapter(Activity context, int textViewResourceId,
            ArrayList<MediaModel> objects) {
        super(context, textViewResourceId, objects);
        this.medias = objects;
        this.context = context;
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        options = new DisplayImageOptions.Builder()
        .showImageOnLoading(R.drawable.ic_launcher)
        .showImageForEmptyUri(R.drawable.ic_launcher)
        .showImageOnFail(R.drawable.ic_launcher).cacheInMemory(true)
        .cacheOnDisc(true).considerExifParams(true)
        .bitmapConfig(Bitmap.Config.RGB_565).build();
    }

    staticclassViewHolder {
        TextView title;
        TextView description;
        ImageView iconImage;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;

        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.link_row, null);

            holder = new ViewHolder();
            holder.title = (TextView) v.findViewById(R.id.txt_row_title);
            holder.description = (TextView) v.findViewById(R.id.txt_row_description);
            holder.iconImage = (ImageView) v.findViewById(R.id.img_row_icon);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }

        holder.title.setText(medias.get(position).mediaTitle);
        holder.description.setText(medias.get(position).mediaInfo);
        imageLoader.displayImage(medias.get(position).mediaThumbImgUrl, holder.iconImage,options);

        return v;
    }

}

Post a Comment for "Loading Images To Custom Listview - How To Gradually Load?"