我正在使用 Rrtrofit 处理聊天应用程序。通过关注Sendbird我创建聊天对话活动。问题是我不明白如何显示对话的图像。特别是当聊天应用程序图像可以随机出现时。在博客上显示如果我尝试为发件人和收件人视图设置imageView,但不了解如何处理它。
这是我的RecyclerView.ViewHolder:
UIImage
我可以看到我分别为Sender和Receiver工作,因此以下代码是 SentMessageHolder
public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
View view;
if (viewType == VIEW_TYPE_MESSAGE_SENT) {
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_message_sent, parent, false);
return new SentMessageHolder(view);
} else if (viewType == VIEW_TYPE_MESSAGE_RECEIVED){
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_message_received, parent, false);
return new ReceivedMessageHolder(view);
}
return null;
}
// Passes the message object to a ViewHolder so that the contents can be bound to UI.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Datum2 message = (Datum2) data.get(position);
switch (holder.getItemViewType()) {
case VIEW_TYPE_MESSAGE_SENT:
((SentMessageHolder) holder).bind(message);
break;
case VIEW_TYPE_MESSAGE_RECEIVED:
((ReceivedMessageHolder) holder).bind(message);
}
}
以及我的 ReceivedMessageHolder 是:
private class SentMessageHolder extends RecyclerView.ViewHolder {
TextView messageText, timeText;
String rec_id;
String content_id;
int[] ids = new int[100];
SentMessageHolder(final View itemView) {
super(itemView);
messageText = itemView.findViewById(R.id.text_message_body);
timeText = itemView.findViewById(R.id.text_message_time);
}
void bind(Datum2 message) {
messageText.setText(message.getMsg());
// Format the stored timestamp into a readable String using method.
timeText.setText(message.getCreatedAt().getFormatTime());
content_id = message.getContentId().toString();
if (! message.getOriginatorId().equals(userID)){
rec_id.valueOf(message.getOriginatorId());
}
else {
rec_id = null;
}
}
}
这是我的图像模态类:
private class ReceivedMessageHolder extends RecyclerView.ViewHolder {
TextView messageText, timeText, nameText;
ImageView profileImage;
ReceivedMessageHolder(View itemView) {
super(itemView);
messageText = itemView.findViewById(R.id.text_message_body);
timeText = itemView.findViewById(R.id.text_message_time);
nameText = itemView.findViewById(R.id.text_message_name);
profileImage = itemView.findViewById(R.id.image_message_profile);
}
void bind(Datum2 message) {
messageText.setText(message.getMsg());
// Format the stored timestamp into a readable String using method.
timeText.setText(message.getCreatedAt().getFormatTime());
nameText.setText(message.getOriginator().getFullName());
// Insert the profile image from the URL into the ImageView.
Glide.with(mContext).load("my website url" + data.get(getLayoutPosition())
.getOriginator().getAvatar()).apply(RequestOptions.circleCropTransform())
.into(profileImage);
}
}
我的json是这样的:
public class Attributes {
@SerializedName("sticker")
@Expose
private String sticker;
@SerializedName("images")
@Expose
private List<String> images;
public String getSticker() {
return sticker;
}
public void setSticker(String sticker) {
this.sticker = sticker;
}
public List<String> getImages() {
return images;
}
public void setImages(List<String> images) {
this.images = images;
}
}
那么在我的对话中如何检索我的图像呢?需要帮忙。