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

android getview method error with glide image download

我在 glide 下载图片时遇到问题

错误图像视图未集成并且 c.getPhotourl("")// 有错误

错误所在行:

Glide.with(context).load("http://dummyimage.com/100x100.png/cc0000/ffffff"+busViewHolder.imageView.setImageResource(c.getPhotourl("")).into(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);
    }
} 

试试这个:

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

您正在使用在 getView() 中声明但未初始化的 ImageView it.Thats 为什么 return 错误 imageView 未初始化。尝试使用 busViewHolder.ImageView.

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