@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
Chapter chapter = chapters.get(position);
String toDay = chapter.chapterName + " " + chapter.month + " " + chapter.year;
if (arr!=null) {
for (String s : arr) {
if (toDay.equals(s)) {
holder.linear.setBackgroundResource(R.drawable.subscripti);
}
}
}
如果我在适配器类的onbindView中循环,则每次打印时尝试滚动schoing和recyclerview滚动不平滑android时循环响应
最佳答案
数组的时间复杂度为 O(n),HashSet 的时间复杂度为 O(1),因此在这种情况下最好使用 HashSet。
你可以这样做:
1- 将所有日期添加到 HashSet 中:
Set<String> days = new HashSet<>();
days.add("12 january 2019");
days.add("14 january 2019");
2-然后将其传递给您的适配器并检查此哈希集是否包含当前日期
if(days.contains(today)){
// Do what you want
}
关于java - 如果我在适配器类 android 的 onbindView 中循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60868131/