getView方法中的imageloader出错

时间:2014-11-03 11:42:05

标签: android adapter universal-image-loader getview

我想使用图像加载器解析xml中的图像,但是在getView()方法中我得到了这个错误:

  

java.lang.IllegalArgumentException:view不能为null

这是我的getView()方法:

 final ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),R.layout.row_site, R.id.nameTxt, result){
            public View getView(int position, View convertView, ViewGroup parent) {

                View view = super.getView(position, convertView, parent);

                ImageView left = (ImageView)getActivity().findViewById(R.id.img);
             String bit = result.get(position).getThumb();
                   //     Picasso.with(getActivity()).load(bit).into(left);

             DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                        .cacheOnDisc(true).cacheInMemory(true)
                        .imageScaleType(ImageScaleType.EXACTLY)
                        .displayer(new FadeInBitmapDisplayer(300)).build();

                ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                        getActivity().getApplicationContext())
                        .defaultDisplayImageOptions(defaultOptions)
                        .memoryCache(new WeakMemoryCache())
                        .discCacheSize(100 * 1024 * 1024).build();

                ImageLoader.getInstance().init(config);


                 imageLoader = ImageLoader.getInstance();
                DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
                        .cacheOnDisc(true).resetViewBeforeLoading(true)
                        .build();
                //imageView.setImageAlpha(120);
                //imageView.setColorFilter(Color.BLUE, PorterDuff.Mode.LIGHTEN);

                imageLoader.displayImage(result.get(position).getThumb(), left, defaultOptions);


                return view;
            }

        };

        setListAdapter(adapter);
        ListView list = getListView();

2 个答案:

答案 0 :(得分:1)

尝试这样,

final ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),R.layout.row_site, R.id.nameTxt, result){
            public View getView(int position, View convertView, ViewGroup parent) {

                LayoutInflater inflater = LayoutInflater.from(getActivity());
                convertView = inflater.inflate(R.layout.row_site, null, false);

                ImageView left = (ImageView) convertView.findViewById(R.id.img);
             String bit = result.get(position).getThumb();
                   //     Picasso.with(getActivity()).load(bit).into(left);

             DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                        .cacheOnDisc(true).cacheInMemory(true)
                        .imageScaleType(ImageScaleType.EXACTLY)
                        .displayer(new FadeInBitmapDisplayer(300)).build();

                ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                        getActivity().getApplicationContext())
                        .defaultDisplayImageOptions(defaultOptions)
                        .memoryCache(new WeakMemoryCache())
                        .discCacheSize(100 * 1024 * 1024).build();

                ImageLoader.getInstance().init(config);


                 imageLoader = ImageLoader.getInstance();
                DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
                        .cacheOnDisc(true).resetViewBeforeLoading(true)
                        .build();
                //imageView.setImageAlpha(120);
                //imageView.setColorFilter(Color.BLUE, PorterDuff.Mode.LIGHTEN);

                imageLoader.displayImage(result.get(position).getThumb(), left, defaultOptions);


                return convertView;
            }

        };

答案 1 :(得分:1)

您不是在夸大视图 像这样膨胀

LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(activity.LAYOUT_INFLATER_SERVICE);
            rowitems = inflater.inflate(R.layout.transport_list_items, null);

如果你想我可以发帖剪掉完整的代码。