【问题标题】:How to add items from a List< > to another List< > using the same model如何使用相同的模型将列表<>中的项目添加到另一个列表<>
【发布时间】:2019-07-04 14:54:10
【问题描述】:

我有 2 个列表,我需要使用相同的列表将项目从一个列表传递到另一个列表 模型,在这种情况下,我们称之为回复。

每个回复都有一个uid,如果我提供的uid等于回复的uid,它应该把那个项目复制到currentReply列表中

List<Replies> allReplies;  //All replies are here
List<Replies> currentReply; //Replies that meet criteria should be added here

String prov_uid = 123456;
Replies replies = getValue(Replies.class);

if (allReplies.equals(prov_uid))
{
    currentReply.add()
}

【问题讨论】:

  • 如果条件满足,循环allReplies并添加到currentReply
  • 发布回复shema。

标签: android list arraylist


【解决方案1】:

这应该可以工作

for (Replies item : allReplies){
    if (<your condition>){
        currentReply.add(item);
    }
}

【讨论】:

  • 如何正确设置 onBindviewHolder ,它会返回视觉故障
  • 我试过 i String m = mReplies.get(getAdapterPosition()).getComment_uid();但它抛出了这个错误:java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1 at java.util.ArrayList.get(ArrayList.java:439) at apps.stylizedAdapters.CommentsAdapter$ViewHolder.(CommentsAdapter.java:539)
猜你喜欢
  • 2013-03-25
  • 1970-01-01
  • 1970-01-01
  • 2021-12-22
  • 2021-02-23
  • 2021-08-18
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
相关资源
最近更新 更多