我在做聊天应用程序。我想将新出现的消息项放在RecyclerView的顶部位置。为此,我想将即将发送的Id与存储在ArrayList特定位置的所有Id进行匹配。如何在“我的代码”中搜索包含位置的ID。请一些想法。 我的代码在
之下 @Override
public void onBindViewHolder(ChatViewHolder holder, final int position) {
if (chatList.get(position).modelType == ChatMasterModel.TYPE_USER) {
try {
final ChatUserModel userModel = (ChatUserModel) chatList.get(position).modelObj;
holder.tvBuddyName.setText(userModel.getUserName() + " " + userModel.getUserLastName());
final String complete_name = userModel.getUserName() + " " + userModel.getUserLastName();
new ImageLoader(activity).DisplayImage(userModel.getUser_image(), holder.ivChatProfilePic, R.drawable.person_icon);
holder.chatBuddyList.llChatBuddyItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, ChatBuddtDetailsActivity.class);
intent.putExtra("user_id", userModel.getUserId());
intent.putExtra("header_name", complete_name);
intent.putExtra("user_image", userModel.getUser_image());
activity.startActivity(intent);
}
});
} catch (Exception e) {
}
} else if (chatList.get(position).modelType == ChatMasterModel.TYPE_GROUP) {
try {
final ChatGroupModel groupModel = (ChatGroupModel) chatList.get(position).modelObj;
new ImageLoader(activity).DisplayImage(groupModel.getGroup_iamge(), holder.ivChatProfilePic, R.drawable.person_icon);
holder.tvBuddyName.setText(groupModel.getGroupMembers());
/* if (msg_from.contains(groupModel.getGroupMemberId())) {
Toast.makeText(activity, "Group contains ID", Toast.LENGTH_SHORT).show();
}*/
holder.chatBuddyList.llChatBuddyItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, ChatBuddtDetailsActivity.class);
intent.putExtra("group_id", groupModel.getGroup_id());
intent.putExtra("group_member_id", groupModel.getGroupMemberId());
intent.putExtra("header_name", groupModel.getGroupMembers());
intent.putExtra("user_image", groupModel.getGroup_iamge());
activity.startActivity(intent);
}
});
} catch (Exception e) {
}
}
}
@Override
public int getItemCount() {
return chatList.size();
}
@Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
}
}
答案 0 :(得分:0)
将时间戳存储在带有时间戳的arralist和sort数组中,然后发送到recyclerview addafter然后发送给notifyadapter