无法从firebase存储可下载url检索图像如何在holder中检索和设置imageview?

hwamh0ep  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(230)

adapter.java类位于:

public class LesionAdapter extends BaseAdapter {

ArrayList<usersickness> lesionList;
Context context;
LayoutInflater vi;

public LesionAdapter(Context context, ArrayList<usersickness> lesions) { //, LayoutInflater layoutInflater
    this.lesionList = lesions;
    this.context = context;
    this.vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

@Override
public Object getItem(int i) {
    return lesionList.get(i);
}

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

@Override
public View getView(final int i, View convertView, ViewGroup viewGroup) { //convertview -> view
    ViewHolder holder;

    if(convertView == null){
        holder = new ViewHolder();

        convertView = vi.inflate(R.layout.lesion_item, null);
        holder.img = convertView.findViewById(R.id.les_img);
        holder.name = convertView.findViewById(R.id.les_name);
        holder.date = convertView.findViewById(R.id.les_date);
        holder.area = convertView.findViewById(R.id.les_area);
        holder.number = convertView.findViewById(R.id.les_number);
        holder.checkBox = convertView.findViewById(R.id.les_checkBox);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    String path = lesionList.get(i).getPhoto_id();
    Glide.with(context).load(path).into(holder.img);
    Picasso.get().load(path).resize(140,140).centerCrop().into(holder.img);
    holder.img.setImageResource(R.drawable.rosacea1);
    holder.name.setText(lesionList.get(i).getClassificationNameRatio());
    holder.date.setText(lesionList.get(i).getDate());
    holder.area.setText(lesionList.get(i).getSegLesionArea());
    holder.number.setText(lesionList.get(i).getSegLesionNumber());
    holder.checkBox.setChecked(lesionList.get(i).getCheckBox());

    holder.checkBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean isSelected = ((CheckBox)v).isChecked();
            lesionList.get(i).setCheckBox(isSelected);
        }
    });

    return convertView;

}

static class ViewHolder {
    public ImageView img;
    public TextView name;
    public TextView date;
    public TextView area;
    public TextView number;
    public CheckBox checkBox;
}

public ArrayList<usersickness> getSelectLesionList(){
    ArrayList<usersickness> list = new ArrayList<>();
    for(int i=0;i<lesionList.size();i++){
        if(lesionList.get(i).getCheckBox())
            list.add(lesionList.get(i));
    }
    return list;
}

build.gradle依赖关系如下:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.firebase:firebase-database:19.4.0'
implementation 'com.google.firebase:firebase-storage:19.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.jjoe64:graphview:4.2.2'
implementation files('libs/activation.jar')
implementation files('libs/additional.jar')
implementation files('libs/mail.jar')
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'com.squareup.picasso:picasso:2.71828'

implementation 'com.github.bumptech.glide:glide:4.11.0'

implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'

我从firebase存储中检索可下载的图像URL。url的格式如下:https://firebasestorage.googleapis.com/v0/b/[projectid].appspot.com/o/[foldername]%2f[文件名]
然后我将url路径放在picasso和glide模块中,但它们不起作用。以前以列表视图的形式工作的代码,现在不列出任何内容。页面为空,其他文本视图不可见。现在只看到按钮。
我需要帮助,因为我不知道问题出在哪里。
你能帮我修一下吗?或者如何从存储器中获取图片并在imageview中显示?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题