gpt4 book ai didi

java - Recyclerview 有条件点击

转载 作者:行者123 更新时间:2023-12-02 10:37:00 25 4
gpt4 key购买 nike

enter image description here

代码

@Override
protected void onBindViewHolder(@NonNull final Chat.MessagesViewHolder holder, final int position, @NonNull final MessagesHelper model) {
holder.setMessage(model.getMessage());
final String userId = getRef(position).getKey();
final DatabaseReference mTimeReference = FirebaseDatabase.getInstance().getReference().child("Messages").child(MessageSenderId).child(MessageRecieverId);
Query messageQuery = mTimeReference.limitToLast(10);
messageQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
final String from_user = model.getFrom();
final boolean Seen = model.isSeen();
MessagesHelper message = dataSnapshot.getValue(MessagesHelper.class);
messagesList.add(message);
messageList.scrollToPosition(messagesList.size() - 1);
}

模态

public class MessagesHelper {
private String From;
private String Message;
private String Type;
private boolean Seen;
private boolean Online;
private long Time;

public MessagesHelper() {
}

public MessagesHelper(String From, String Message, String Type, boolean Seen, boolean Online, long Time) {
this.From = From;
this.Message = Message;
this.Type = Type;
this.Seen = Seen;
this.Online = Online;
this.Time = Time;
}

public String getFrom() {
return From;
}

public void setFrom(String from) {
this.From = from;
}

public String getMessage() {
return Message;
}

public void setMessage(String message) {
this.Message = message;
}

public String getType() {
return Type;
}

public void setType(String type) {
this.Type = type;
}

public boolean isSeen() {
return Seen;
}

public void setSeen(boolean seen) {
this.Seen = seen;
}

public boolean isOnline() {
return Online;
}

public void setOnline(boolean Online) {
this.Online = Online;
}
public long getTime() {
return Time;
}

public void setTime(long time) {
this.Time = time;
}

}

如果类型 =“链接”,我希望该项目可点击...我怎样才能实现这一点???

最佳答案

您可以像这样检查类型并将项目 View 设置为可点击。

if(type.equals("Link"))
{
holder.itemView.setClickable(true);
holder.itemView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
// do smoethink
}
});
}
else
{
holder.itemView.setClickable(false);
}

关于java - Recyclerview 有条件点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53207545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com