如何将DiffUtil与多种视图类型一起使用

时间:2020-05-10 21:34:54

标签: android android-studio android-recyclerview android-diffutils

我已经实现了具有多种视图类型的recyclerview,并且我想添加DiffUtil。我设法做到了一种,但是当我尝试支持多种视图类型时,我不能

所以我的问题是:DiffUtil是否支持多种视图类型,并且有关于Java实现的好教程

我的适配器

public search(message: Message) {
    let search: string;
    const filter = (msg: Message) => msg.author.id === message.author.id;
    message.channel.send('Enter search term').then(msg => {
      message.channel.awaitMessages(filter, { max: 1 })
        .then(collected => {
            if (collected.first()!.content === 'Test') this.search(message);
            msg.delete()
            collected.first()!.delete()
            search = collected.first()!.content
          })
        })
    })
    return search; // Variable 'search' is used before being assigned.ts(2454)
  }

1 个答案:

答案 0 :(得分:0)

DiffUtil不会干扰您的视图,只有模型来自适配器。看来您想对postList进行区分,其中包含不同类型的类型(项目,广告等)

对于DiffUtil.ItemCallback<Object>类型,您可以像在getItemViewType中一样使用Object