尝试使用picasso显示FirebaseFirestore中的图像时出错



我正在尝试显示firebasefirestore中的图像和文本。文本显示得很好,但我一直在尝试显示图像。显示图像的正确方式是什么,因为我所遵循的教程似乎不到位或遗漏了什么我试着寻找一些答案,但没有得到足够的帮助以下是我的主要活动和模型类

主要活动

package com.example.tutorscape;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
private RecyclerView mFirebaseList;
private FirebaseFirestore firebaseFirestore;
private FirestoreRecyclerAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseFirestore=FirebaseFirestore.getInstance();
mFirebaseList= findViewById(R.id.recyclerView);

Query query = firebaseFirestore.collection("Admin");

FirestoreRecyclerOptions<Model> options = new FirestoreRecyclerOptions.Builder<Model>()
.setQuery(query,Model.class)
.build();
adapter= new FirestoreRecyclerAdapter<Model, MyViewHolder>(options) {
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
return new MyViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull Model model) {

holder.list_name.setText(model.getName());
holder.list_title.setText(model.getTitle());
//  Picasso.get().load(model.getImage()).into(imageView);

}
};

mFirebaseList.setHasFixedSize(true);
mFirebaseList.setLayoutManager(new LinearLayoutManager(this));
mFirebaseList.setAdapter(adapter);
}
private class MyViewHolder extends RecyclerView.ViewHolder{
private TextView list_name;
private TextView list_title;
//  private ImageView imageView;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
list_name=itemView.findViewById(R.id.textViewName);
list_title=itemView.findViewById(R.id.textViewTitle);
//     imageView=itemView.findViewById(R.id.imageView);
}
}

@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}

型号类别

package com.example.tutorscape;
public class Model {
private String name;
private String title;
private String image;
private Model(){}
public Model(String name, String title,String image) {
this.name = name;
this.title = title;
this.image=image;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

图像的URL在浏览器中打开良好

取消注释所有内容&将imageView删除到holder.imageViewPicasso.get((.加载(model.getImage(((.到(imageView(

我想你必须这样调用Picasso

Picasso.get().load(model.getImage()).into(holder.imageView);

这就像调用holder.list_name来设置文本一样

取消注释这些行,这是正确的。

private ImageView imageView;
imageView=itemView.findViewById(R.id.imageView);


希望它现在有效!

相关内容

  • 没有找到相关文章

最新更新