ここでは、Storageを指すURLを保存し、次にGlideをリサイクラビューにダウンロードする例を示します。
// Chat message text can contain a download URL or text
public class ChatMessage {
public String name;
public String message;
public ChatMessage() {
}
public ChatMessage(String name, String message) {
this.name = name;
this.message = message;
}
}
// Use a custom ViewHolder populated from the chat message
public class ChatMessageViewHolder extends RecyclerView.ViewHolder {
private static final String TAG = "ChatMessageViewHolder";
private final Activity activity;
TextView name, message;
ImageView image;
public ChatMessageViewHolder(Activity activity, View itemView) {
super(itemView);
this.activity = activity;
name = (TextView) itemView.findViewById(android.R.id.text1);
message = (TextView) itemView.findViewById(android.R.id.text2);
image = new ImageView(activity);
((ViewGroup)itemView).addView(image);
}
public void bind(ChatMessage chat) {
name.setText(chat.name);
if (chat.message.startsWith("https://firebasestorage.googleapis.com/") || chat.message.startsWith("content://")) {
message.setVisibility(View.INVISIBLE);
image.setVisibility(View.VISIBLE);
// Use Glide (you could use Picaso) to load the image
Glide.with(activity)
.load(chat.message)
.into(image);
}
else {
message.setVisibility(View.VISIBLE);
image.setVisibility(View.GONE);
message.setText(chat.message);
}
}
}
This gistと
iがhttps://youtu.be/BRrMUcuR_fQをrecyleradupter firebase画像を取得する方法についてのビデオを作る完全なアプリでこれを行う方法をthis video詳細 – Hamza