我试图将图片文件作为字符串发布,将标题作为字符串发布。 我成功地能够在数据库中写入标题和图像字符串,但不知道如何让它在我的recyclerview中显示图像文件
public class FireBaseReadWrite {
private static final String TAG = "FirebaseReadWrite";
// Firebase instance variables
DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference listRef = mRootRef.child("post");
// When a user go offline this code will keep there saved data on the device
// FirebaseDatabase.getInstance().setPersistenceEnabled(true);
public FireBaseReadWrite writeFirebase(String title,String imageURL){
Post post = new Post(title,imageURL);
mRootRef.child("posts").setValue(post);
return null;
}
public void readFirebase(){
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI
Post post = dataSnapshot.getValue(Post.class);
Log.w(TAG, String.valueOf(post));
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
// mPostReference.addValueEventListener(postListener); }
}
答案 0 :(得分:0)
我建议您使用Picasso库http://square.github.io/picasso/ 用于图像加载。
假设您从firebase数据库获得了Image url,即http://i.imgur.com/DvpvklR.png
String img_url = "http://i.imgur.com/DvpvklR.png";
使用库将其加载到您的imageView(放入您的recyclerView)中,如
Picasso.with(context).load(img_url).into(imageView);