当我想显示来自Firebase的文本和图像时出现问题,文本可能会出现,而图像无法显示。
这是我的模型班级:
public class Model {
String title, image, description;
//constructor
public Model(){}
//getter and setters press Alt+Insert
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
这是我的视图持有人课程
public class ViewHolder extends RecyclerView.ViewHolder {
View mView;
public ViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setDetails (Context ctx, String title, String description, String image){
//Views
TextView mTitleTv = mView.findViewById(R.id.rTitleTv);
TextView mDetailTv = mView.findViewById(R.id.rDescriptionTv);
ImageView mImageIv = mView.findViewById(R.id.rImageView);
//set data to views
mTitleTv.setText(title);
mDetailTv.setText(description);
Picasso.get().load(image).into(mImageIv);
}
}
这是我的主要活动
package com.ainuralizar.firebaseproject;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class PostListActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
DatabaseReference mRef;
FirebaseDatabase mFirebaseDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_list);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("post list");
mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mFirebaseDatabase = FirebaseDatabase.getInstance();
mRef = mFirebaseDatabase.getReference("Data");
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Model,ViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<Model, ViewHolder>(Model.class,R.layout.row , ViewHolder.class ,mRef) {
@Override
protected void populateViewHolder(ViewHolder viewHolder, Model model, int position) {
viewHolder.setDetails(getApplicationContext(),model.getTitle(),model.getDescription(),model.getImage());
}
};
mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}
我已尝试更改数据,但仍无法显示存储在Firebase中的图像。我希望你们有一个解决方案,对不起,英语不好。
我想从Firebase显示文本和图像时遇到问题,文本可能会出来,而图像无法显示。这是我的模型类:公共类Model {字符串标题,图像,...
您使用的图像URL无效,图像URL应该以https://
或http://
开头