在回收视图中,我正在通过此查询加载数据,它加载得很好。但是向下滚动后,它变得分散了。
Query query = db.collection(USER_MASTER_KEY)
.document(Uid)
.collection("following")
.document(xpertId)
.collection("chat_transcript")
.orderBy(TIMESTAMP_KEY);
这是我的onBind方法。在这里,我同时加载图像,文本,视频。我在聊天机器人应用程序中构建了此回收站。数据的响应先前已加载到firebase中。根据这个问题,ans将被加载。所有的内容都会被加载,但是在出现两个三个视频加载问题之后。
@Override
public void onBindViewHolder(@NonNull final ChatViewHolder holder, int position) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
final ChatViewData chatViewData1 = chatViewDataList.get(position);
klog.d("## CHAT ITEM-", new Gson().toJson(chatViewData1));
String chatData = chatViewData1.getMsgContent();
// If the message is still pending show placeholder
if (chatViewData1.MSG_TYPE_PACEHOLDER.equalsIgnoreCase(chatViewData1.getMsgType())) {
holder.gifImageViewLoading.setVisibility(VISIBLE);
holder.leftMsgTextView.setVisibility(GONE);
holder.rightMsgTextView.setVisibility(GONE);
holder.leftImageView.setVisibility(GONE);
holder.relativeLayout.setVisibility(GONE);
}
// If the message type is blank, show nothing
if (chatViewData1.getMsgType().equalsIgnoreCase("")) {
holder.gifImageViewLoading.setVisibility(GONE);
holder.leftMsgTextView.setVisibility(GONE);
holder.rightMsgTextView.setVisibility(GONE);
holder.leftImageView.setVisibility(GONE);
holder.relativeLayout.setVisibility(GONE);
}
// If the message is a received message.
if (chatViewData1.MSG_TYPE_RECEIVED.equals(chatViewData1.getMsgType())) {
holder.leftMsgTextView.setText(HtmlCompat.fromHtml(chatData, HtmlCompat.FROM_HTML_MODE_COMPACT), TextView.BufferType.SPANNABLE);
holder.gifImageViewLoading.setVisibility(GONE);
holder.leftMsgTextView.setVisibility(VISIBLE);
//holder.chatLikeOption.setVisibility(VISIBLE);
//holder.chatDislikeOption.setVisibility(VISIBLE);
holder.rightMsgTextView.setVisibility(GONE);
holder.leftImageView.setVisibility(GONE);
holder.relativeLayout.setVisibility(GONE);
}
// If the message is a sent message.
else if (chatViewData1.MSG_TYPE_SENT.equals(chatViewData1.getMsgType())) {
holder.rightMsgTextView.setText(HtmlCompat.fromHtml(chatData, HtmlCompat.FROM_HTML_MODE_COMPACT), TextView.BufferType.SPANNABLE);
holder.gifImageViewLoading.setVisibility(GONE);
holder.rightMsgTextView.setVisibility(VISIBLE);
holder.leftMsgTextView.setVisibility(GONE);
holder.leftImageView.setVisibility(GONE);
holder.relativeLayout.setVisibility(GONE);
}
// If the message is an image message.
else if (chatViewData1.MSG_TYPE_IMAGE.equals(chatViewData1.getMsgType())) {
//Load Image using Picasso library
Picasso.get().load(chatViewData1.getMsgContent()).into(holder.leftImageView);
holder.gifImageViewLoading.setVisibility(GONE);
holder.leftImageView.setVisibility(VISIBLE);
holder.rightMsgTextView.setVisibility(GONE);
holder.leftMsgTextView.setVisibility(GONE);
holder.relativeLayout.setVisibility(GONE);
}
// If the message is a video message.
else if (chatViewData1.MSG_TYPE_VIDEO.equals(chatViewData1.getMsgType())) {
final String videoId = chatViewData1.getMsgContent();
final ImageView yimageView = holder.YoutubeImageView;
final String url = "https://img.youtube.com/vi/" + videoId + "/default.jpg";
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bm = loadBitmap(url, bmOptions);
yimageView.setVisibility(VISIBLE);
//holder.videoLikeOption.setVisibility(VISIBLE);
//holder.videoDislikeOption.setVisibility(VISIBLE);
yimageView.setImageBitmap(bm);
yimageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent("custom-message");
// intent.putExtra("quantity",Integer.parseInt(quantity.getText().toString()));
intent.putExtra("startTime", chatViewData1.getStartSeconds());
intent.putExtra("endTime", chatViewData1.getEndSeconds());
intent.putExtra("videoId", videoId);
LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
}
});
}
}
在recycleview的适配器上使用这两种方法
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return position;
}