gpt4 book ai didi

android - 从另一个类更新 RecyclerView

转载 作者:太空狗 更新时间:2023-10-29 13:48:35 24 4
gpt4 key购买 nike

我会尽量简短:

我有三个类必须在此交互:

  1. 服务器,它接收消息(在线程中)。
  2. 联系人,它在其类中(在每个对象中)存储消息。
  3. 属于每个用户的聊天 Activity ,必须显示相应对象的消息,其思想是它是一个RecyclerView。(一个 Activity )

服务器收到一条消息,这条消息将被添加到特定联系人的聊天中,然后必须更新 RecyclerView。

这是基本的联系人类代码:

public class Contact implements Serializable {

private String name;
private String ip;
//Here would be a variable that contains the chat strings

public Contact (String name, String ip){
this.name = name;
this.ip = ip;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}
}

然后是在选择特定用户时启动的聊天 Activity ,它包含我希望消息所在的 RecyclerView。

My problem is that, how to make the messages that are stored in the variable of a specific object appear in the list.

从已经非常感谢你。

最佳答案

你可以使用数据类而不是序列化

public class Data {

private String text;
private String uid;
private String tnviews;
private String numberlikes;
public Data(String text,String tnviews,String numberlikes,String uid) {
this.text = text;
this.tnviews = tnviews;
this.numberlikes = numberlikes;
this.uid = uid;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
/////////// VIEWS
public String getViews() {
return tnviews;
}

public void setViews(String tnviews) {
this.tnviews = tnviews;
}
//////// likes
public String getLikes() {
return numberlikes;
}

public void setLikes(String numberlikes) {
this.numberlikes = numberlikes;
}

public String getUid() {
return uid;
}

public void setUid(String uid) {
this.uid = uid;
}

关于android - 从另一个类更新 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50206472/

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