简体   繁体   English

Android:通用图片加载器

[英]Android : Universal image Loader

I want to show images using Android Universal Image Loader. 我想使用Android Universal Image Loader显示图像。 I want to show images from internal storage in HorizontalScrollView but images are not show even i get the path of internal storage.Here is my code. 我想在Horizo​​ntalScrollView中显示来自内部存储的图像,但是即使我获得内部存储的路径也无法显示图像。这是我的代码。

Here is My Adapter class 这是我的适配器类

 class MyListAdapter extends ArrayAdapter<All_Post> {
    Context context;
    int layoutResourceId;
    private ImageLoader imageLoader;
    private ImageLoaderConfiguration config;
    private DisplayImageOptions options;


    ArrayList<All_Post> data = new ArrayList<All_Post>();

    public MyListAdapter(Context context, int layoutResourceId, ArrayList<All_Post> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;

        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));

        options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.img_placeholder)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new FadeInBitmapDisplayer(300))
                .build();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        final Holder holder;
        if (row == null) {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            row = vi.inflate(R.layout.all_post_row, null);
            holder = new Holder();
 holder.horizontalScrollView = (HorizontalScrollView) row.findViewById(R.id.hlist);
            holder.lLinearLayout = (LinearLayout) row.findViewById(R.id.innerlay);
            row.setTag(holder);
        } else {
            holder = (Holder) row.getTag();
        }
 holder.lLinearLayout.removeAllViews();
        final Iterator<String> it = imageArray.iterator();
        while (it.hasNext())
        {
 if (imgElement.endsWith(png_Pattern) || imgElement.endsWith(jpg_pattern) || imgElement.endsWith(bmp_pattern) || imgElement.endsWith(gif_pattern) || imgElement.endsWith(jpeg_pattern))
            {
                LayoutInflater mInflater;
                mInflater = LayoutInflater.from(getContext());
                View cur_deal = mInflater.inflate(R.layout.horizontalitem, holder.lLinearLayout, false);

                final ImageView imageView = (ImageView) cur_deal.findViewById(R.id.image_AllPost);
                imageView.setImageResource(R.drawable.img_placeholder);

                pBar = (ProgressBar) cur_deal.findViewById(R.id.pBar_AllPost);
                pBar.setVisibility(View.VISIBLE);

                holder.lLinearLayout.addView(cur_deal);

 Log.e("imgElement*************", " = " + imgElement);
                String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
                String path = baseDir + "/classnkk_images/" + imgElement;
                Log.e("path ", " = " + path);

                File photos = new File(path);
                final Bitmap bitmapResizeImage = decodeFile(photos);

                long length = photos.length();
                length = length/1024;
                Log.e("png_Pattern length ", " = " + length);
                if(length != 0 || length > 0)
                {

 Log.e("imgElement*************", " = " + imgElement);
                            //String baseDir1 = Environment.getExternalStorageDirectory().getAbsolutePath();
                            String baseDir1 = Environment.getDataDirectory().getAbsolutePath();
                            String path1 = baseDir1 + "/classnkk_images/" + imgElement;
                            Log.e("path ", " = " + path);

                            String str_IMAGE_URLS = namespace + "/DownloadFile/FileName/" + imgElement;
                            ImageLoader.getInstance().displayImage(path1, imageView, options, new SimpleImageLoadingListener() {
                                @Override
                                public void onLoadingStarted(String imageUri, View view) {
                                    pBar.setProgress(0);
                                    pBar.setVisibility(View.VISIBLE);
                                }

                                @Override
                                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                                    pBar.setVisibility(View.GONE);
                                }

                                @Override
                                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                                    pBar.setVisibility(View.GONE);
                                }
                            }, new ImageLoadingProgressListener() {
                                @Override
                                public void onProgressUpdate(String imageUri, View view, int current, int total) {
                                    pBar.setProgress(Math.round(100.0f * current / total));
                                }

                            });
                        }

Thanks in advanced 提前致谢

Instead of this... 代替这个...

String str_IMAGE_URLS = namespace + "/DownloadFile/FileName/" + imgElement;
                        ImageLoader.getInstance().displayImage(path1, imageView, options, new SimpleImageLoadingListener() {
                            @Override
                            public void onLoadingStarted(String imageUri, View view) {
                                pBar.setProgress(0);
                                pBar.setVisibility(View.VISIBLE);
                            }

                            @Override
                            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                                pBar.setVisibility(View.GONE);
                            }

                            @Override
                            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                                pBar.setVisibility(View.GONE);
                            }
                        }, new ImageLoadingProgressListener() {
                            @Override
                            public void onProgressUpdate(String imageUri, View view, int current, int total) {
                                pBar.setProgress(Math.round(100.0f * current / total));
                            }

                        });

use this code 使用此代码

String str_IMAGE_URLS = namespace + "/DownloadFile/FileName/" + imgElement;
                        imageLoader.displayImage(str_IMAGE_URLS , imageView, options, new SimpleImageLoadingListener() {
                            @Override
                            public void onLoadingStarted(String imageUri, View view) {
                                pBar.setProgress(0);
                                pBar.setVisibility(View.VISIBLE);
                            }

                            @Override
                            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                                pBar.setVisibility(View.GONE);
                            }

                            @Override
                            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                                pBar.setVisibility(View.GONE);
                            }
                        }, new ImageLoadingProgressListener() {
                            @Override
                            public void onProgressUpdate(String imageUri, View view, int current, int total) {
                                pBar.setProgress(Math.round(100.0f * current / total));
                            }

                        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM