andriod getview方法错误与滑行图像下载

时间:2017-08-13 16:14:59

标签: android android-glide getview

滑行下载图像有问题

erro图片视图未被使用且c.getPhotourl("")//有错误

                  line where is error :

Glide.with(上下文).load(" http://dummyimage.com/100x100.png/cc0000/ffffff&#34 + busViewHolder.imageView.setImageResource(c.getPhotourl(""))代入(ImageView的);

这里是getview方法

public View getView(int position, View convertView, ViewGroup parent) {
        // View v = super.getView(position, convertView, parent);
        // View v = convertView;
        TextView txt1;
        TextView txt2;
        TextView txt3;
        ImageView imageView;



        BusViewHolder busViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.test, null);

            txt1 = (TextView) convertView.findViewById(R.id.id1);
            txt2 = (TextView) convertView.findViewById(R.id.name);
            txt3 = (TextView) convertView.findViewById(R.id.gender);
            imageView = (ImageView) convertView.findViewById(R.id.image);
            busViewHolder = new BusViewHolder(txt1, txt2, txt3);
            convertView.setTag(busViewHolder);
        }
        Contactinfo c = getItem(position);


        busViewHolder = (BusViewHolder) convertView.getTag();

        busViewHolder.txt1.setText(c.getGender());
        //  busViewHolder.txt2.setText(""+c.getId());
        busViewHolder.txt3.setText(c.getFirst_name());
        busViewHolder.txt2.setText(c.getId() + "");

        //busViewHolder.imageView.setImageResource(c.getPhotourl());

       Glide.with(context).load("http://dummyimage.com/100x100.png/cc0000/ffffff"+busViewHolder.imageView.setImageResource(c.getPhotourl("")).into(imageView);
       // String url="https://dummyimage.com/100x100.png/cc0000/ffffff";
        //Glide.with(context).load(url).into(c.getPhotourl(busViewHolder.imageView.setImageResource();));
//


        return convertView;
    }

    class BusViewHolder {
        TextView txt1;
        TextView txt2;
        TextView txt3;
        ImageView imageView;
        // RatingBar rb;


        public BusViewHolder(TextView txt1, TextView txt2, TextView txt3) {
            this.txt1 = txt1;
            this.txt2 = txt2;
            this.txt3 = txt3;
            this.imageView = imageView;
        }
    }

    @Nullable
    @Override
    public Contactinfo getItem(int position) {
        return super.getItem(position);
    }
} 

2 个答案:

答案 0 :(得分:1)

试试这个:

String url="https://dummyimage.com/100x100.png/cc0000/ffffff";
Glide.with(context).load(url).into(busViewHolder.imageView);
//Glide.with(context).load(c.getPhotourl()).into(busViewHolder.imageView); this line get url from model class

答案 1 :(得分:0)

您正在使用在getView()中声明但未初始化它的ImageView。这就是为什么它返回错误imageView未初始化。尝试使用busViewHolder.ImageView。

Glide.with(context).load("http://dummyimage.com/100x100.png/cc0000/ffffff"+busViewHolder.imageView.setImageResource(c.getPhotourl(""))
                .into(busViewHolder.imageView);