我正在开发一个安卓的聊天应用程序,并且 我希望与您聊天的用户的信息能向右对齐,而他们的信息能向左对齐。 .这是让你区分信息属于谁的条件。 我只能把它写在bindview支架上。
if(model.getUidSender().equals(fAuth.getCurrentUser().getUid()))
但我如何将该项目向右或向左对齐?
我有还有思考了一下充气的两个不同布局但我应该在CreateViewHolder中进行操作,在其中我不会有model.getUidSender的值。我怎样才能解决这个问题呢?
This is my complete code:
@Override
protected void onStart() {
super.onStart();
CollectionReference collectRefMessage = FirebaseFirestore.getInstance().collection("roomChat")
.document("rooms")
.collection(chatId).document("message")
.collection("messages");
FirestoreRecyclerOptions<getMessage> options
= new FirestoreRecyclerOptions.Builder<getMessage>()
.setQuery(collectRefMessage.limit(1000).orderBy("date", Query.Direction.ASCENDING), getMessage.class)
.build();
FirestoreRecyclerAdapter<getMessage, getASetMsg> firestoreRecyclerAdapter = new FirestoreRecyclerAdapter<getMessage, getASetMsg>(options) {
@Override
protected void onBindViewHolder(@NonNull @NotNull getASetMsg holder, int position, @NonNull @NotNull getMessage model) {
holder.txtMsgText.setText(model.getText());
holder.dateATime.setText(model.getDate());
// uidCh = model.getUidSender();
//if(model.getUidSender().equals(fAuth.getCurrentUser().getUid()))
@NonNull
@NotNull
@Override
public getASetMsg onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_chat,parent,false);
getASetMsg viewHolder = new getASetMsg(view);
return viewHolder;
rView.setAdapter(firestoreRecyclerAdapter);
firestoreRecyclerAdapter.startListening();
public static class getASetMsg extends RecyclerView.ViewHolder {
TextView txtMsgText, dateATime;
public getASetMsg(@NonNull View itemView) {
super(itemView);
txtMsgText = itemView.findViewById(R.id.txtMsgText);
dateATime = itemView.findViewById(R.id.dateATime);