- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在创建一个 Android 应用程序来帮助您完成任务。我将 LiveData 与 ListAdapter 一起使用,后者列出了 Fragment 和 DiffUtil 中的所有不同任务,以测试 ListAdapter 中的更改。在解释我的问题之前:这里有一些相关代码:
SubTaskFragment.java:
public class SubTaskFragment extends Fragment {
private RecyclerView recyclerView;
private SubTaskAdapter adapter;
private SubTaskViewModel viewModel;
private static final String TAG = "SubTaskFragment";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment and setup recycler view
View rootView = inflater.inflate(R.layout.fragment_sub_task, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.sub_task_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//set adapter
adapter = new SubTaskAdapter(getContext());
recyclerView.setAdapter(adapter);
viewModel = ViewModelProviders.of(this).get(SubTaskViewModel.class);
viewModel.getSubTasks().observe(getViewLifecycleOwner(), new Observer<List<SubTask>>() {
@Override
public void onChanged(@Nullable List<SubTask> subTasks) {
//Update RecyclerView
Log.d(TAG, "onChanged: subTasks length = " + subTasks.size());
adapter.submitList(subTasks);
}
});
子任务适配器.java
public class SubTaskAdapter extends ListAdapter<SubTask, SubTaskAdapter.ViewHolder> {
private static final String TAG = "SubTaskAdapter";
private SubTaskViewModel subTaskViewModel;
public SubTaskAdapter(Context context) {
super(DIFF_CALLBACK);
this.context = context;
}
private static final DiffUtil.ItemCallback<SubTask> DIFF_CALLBACK = new DiffUtil.ItemCallback<SubTask>() {
@Override
public boolean areItemsTheSame(@NonNull SubTask oldTask, @NonNull SubTask newTask) {
Log.d(TAG, "areItemsTheSame: oldTask name: " + oldTask.getName() + " id: " + oldTask.getId() + " ### newTask name: " + newTask.getName() + " id: " + newTask.getId());
return oldTask.getId() == newTask.getId();
}
@Override
public boolean areContentsTheSame(@NonNull SubTask oldTask, @NonNull SubTask newTask) {
Log.d(TAG, "areContentsTheSame: oldTask name: " + oldTask.getName() + " ### newTask name: " + newTask.getName());
boolean contentsSame = oldTask.getName().equals(newTask.getName()) &&
oldTask.getDueDate().equals(newTask.getDueDate()) &&
oldTask.isCompleted() == newTask.isCompleted() &&
oldTask.getMainTaskId() == (newTask.getMainTaskId());
Log.d(TAG, "areContentsTheSame: = " + contentsSame);
return contentsSame;
}
};
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
SubTask subTask = getItem(i);
Log.d(TAG, "onBindViewHolder: pos: " + i + " name: " + subTask.getName() + " Is overdue: " + subTask.isOverdue());
Log.d(TAG, "onBindViewHolder: " + subTask.getName() + " isOverdue = " + subTask.isOverdue());
//SET BACKGROUND COLOR OF LIST ITEM
if (subTask.isOverdue()) {
viewHolder.card.setCardBackgroundColor(context.getResources().getColor(R.color.red));
viewHolder.subTaskName.setTextColor(context.getResources().getColor(R.color.colorAccent));
viewHolder.mainTaskName.setTextColor(context.getResources().getColor(R.color.colorAccent));
}
if (subTask.isCompleted()) {
viewHolder.checkBox.setChecked(true);
Log.d(TAG, "onBindViewHolder: " + subTask.getName() + " set to checked");
} else {
viewHolder.checkBox.setChecked(false);
Log.d(TAG, "onBindViewHolder: " + subTask.getName() + " set to unchecked");
}
viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG, "onCheckedChanged: called for subTask " + subTask.getName() + " isChecked = " + isChecked);
subTaskViewModel = ViewModelProviders.of((FragmentActivity) context).get(SubTaskViewModel.class);
if (isChecked) {
subTask.setCompleted(true);
subTaskViewModel.updateSubTask(subTask);
} else {
subTask.setCompleted(false);
subTaskViewModel.updateSubTask(subTask);
}
}
});
我遇到的第一个问题是,当用户选中列表项的复选框时,列表项会变成灰色 like so 。这不是预期的行为,因为列表项的颜色不应在检查时更改。未选中时不会发生这种情况。
这是此操作的日志:
2020-01-19 15:24:47.572 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onCheckedChanged: called for subTask Test 1 isChecked = true
2020-01-19 15:24:47.575 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskViewModel: updateSubTask: CALLED for Test 1 isCompleted = true isOverdue = false
2020-01-19 15:24:47.602 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskFragment: onChanged: subTasks length = 5
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read database book id: 1 ### newTask name: Read database book id: 1
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read database book id: 1 ### newTask name: Read database book id: 1
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Wash car ### newTask name: Wash car
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read OS book ### newTask name: Read OS book
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read database book ### newTask name: Read database book
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 1 ### newTask name: Test 1
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = false
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 2 ### newTask name: Test 2
2020-01-19 15:24:47.603 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:47.652 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: pos: 3 name: Test 1 Is overdue: false
2020-01-19 15:24:47.652 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: Test 1 isOverdue = false
2020-01-19 15:24:47.655 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: Test 1 set to checked
2020-01-19 15:24:50.633 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onCheckedChanged: called for subTask Test 1 isChecked = false
2020-01-19 15:24:50.633 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskViewModel: updateSubTask: CALLED for Test 1 isCompleted = false isOverdue = false
2020-01-19 15:24:50.664 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskFragment: onChanged: subTasks length = 5
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read database book id: 1 ### newTask name: Read database book id: 1
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read database book id: 1 ### newTask name: Read database book id: 1
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:24:50.664 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Wash car ### newTask name: Wash car
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read OS book ### newTask name: Read OS book
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read database book ### newTask name: Read database book
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 1 ### newTask name: Test 1
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 2 ### newTask name: Test 2
2020-01-19 15:24:50.665 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
我遇到的下一个可能相关的问题是每当列表项“过期”(红色任务)and I check it off ,ListAdapter 中的其他项目 turn red when I hit it's corresponding checkbox 。这不是它应该发挥作用的方式。这些列表项应该是白色的,因为这些任务没有过期。当我第二次选中/取消选中它时,它最终会再次变回白色。
当检查到过期任务时,应用程序可以正常运行。它会从屏幕上删除,因为我的 SQL SELECT 语句不再返回已检查的过期任务。
这是我两次选中/取消选中未过期列表项时的日志(第 3 个 gif)。这里需要注意的一件重要事情是,当检查测试 1 时,检查列表项时 areContentsTheSame()
会正确返回 false,因为 isCompleted 已从 true 设置为 false。然而,当未选中时,即使 isCompleted 已从 true 设置为 false,areContentsTheSame()
也会错误地返回 true。另外,即使 isOverdue 为 false,列表项也会突然变成红色:
2020-01-19 15:28:52.071 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onCheckedChanged: called for subTask Test 1 isChecked = true
2020-01-19 15:28:52.072 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskViewModel: updateSubTask: CALLED for Test 1 isCompleted = true isOverdue = false
2020-01-19 15:28:52.104 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskFragment: onChanged: subTasks length = 4
2020-01-19 15:28:52.104 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:52.104 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:52.104 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:52.104 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:52.104 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:52.104 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Wash car ### newTask name: Wash car
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read OS book ### newTask name: Read OS book
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 1 ### newTask name: Test 1
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = false
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 2 ### newTask name: Test 2
2020-01-19 15:28:52.105 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:52.136 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: pos: 2 name: Test 1 Is overdue: false
2020-01-19 15:28:52.137 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: Test 1 isOverdue = false
2020-01-19 15:28:52.137 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: Test 1 set to checked
2020-01-19 15:28:54.080 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onCheckedChanged: called for subTask Test 1 isChecked = false
2020-01-19 15:28:54.081 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskViewModel: updateSubTask: CALLED for Test 1 isCompleted = false isOverdue = false
2020-01-19 15:28:54.102 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskFragment: onChanged: subTasks length = 4
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Wash car ### newTask name: Wash car
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read OS book ### newTask name: Read OS book
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 1 ### newTask name: Test 1
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 2 ### newTask name: Test 2
2020-01-19 15:28:54.103 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:58.480 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onCheckedChanged: called for subTask Test 1 isChecked = true
2020-01-19 15:28:58.481 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskViewModel: updateSubTask: CALLED for Test 1 isCompleted = true isOverdue = false
2020-01-19 15:28:58.498 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskFragment: onChanged: subTasks length = 4
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Wash car ### newTask name: Wash car
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read OS book ### newTask name: Read OS book
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 1 ### newTask name: Test 1
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = false
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 2 ### newTask name: Test 2
2020-01-19 15:28:58.499 27375-27504/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:58.529 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: pos: 2 name: Test 1 Is overdue: false
2020-01-19 15:28:58.529 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: Test 1 isOverdue = false
2020-01-19 15:28:58.529 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onBindViewHolder: Test 1 set to checked
2020-01-19 15:28:59.922 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskAdapter: onCheckedChanged: called for subTask Test 1 isChecked = false
2020-01-19 15:28:59.922 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskViewModel: updateSubTask: CALLED for Test 1 isCompleted = false isOverdue = false
2020-01-19 15:28:59.941 27375-27375/com.johnsorhannus.divideandconquer D/SubTaskFragment: onChanged: subTasks length = 4
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 2 id: 5 ### newTask name: Test 2 id: 5
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Test 1 id: 4 ### newTask name: Test 1 id: 4
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Read OS book id: 2 ### newTask name: Read OS book id: 2
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areItemsTheSame: oldTask name: Wash car id: 3 ### newTask name: Wash car id: 3
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Wash car ### newTask name: Wash car
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Read OS book ### newTask name: Read OS book
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 1 ### newTask name: Test 1
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: oldTask name: Test 2 ### newTask name: Test 2
2020-01-19 15:28:59.941 27375-27409/com.johnsorhannus.divideandconquer D/SubTaskAdapter: areContentsTheSame: = true
我注意到的另一件事是,列表中的每个项目都会调用 areItemsTheSame()
两次,而每个列表项目仅调用 areContentsTheSame()
一次。这似乎不是正常行为,因此这可能会以某种方式导致问题。关于这两个问题是否相关以及如何解决它们有什么想法吗?
最佳答案
这里有两个问题。第一个(灰色突出显示)是由于 RecyclerView 内置的默认动画而发生的。当您选中该框时,RecyclerView 会创建一个新的 ViewHolder
并进行交叉淡入淡出。有关如何解决此问题的更多信息,请参阅此问题/答案:RecyclerView.ItemDecoration doesn't update after item is removed from RecyclerView.Adapter
第二个(红色背景)是 onBindViewHolder()
方法中的错误,导致 View 无法正确回收:
if (subTask.isOverdue()) {
viewHolder.card.setCardBackgroundColor(context.getResources().getColor(R.color.red));
viewHolder.subTaskName.setTextColor(context.getResources().getColor(R.color.colorAccent));
viewHolder.mainTaskName.setTextColor(context.getResources().getColor(R.color.colorAccent));
}
像这样的每个 if
语句都需要一个 else
情况来将 View 设置回正常颜色。如果没有这样的else
,您的红色 View 将被回收到另一个位置,并且不会改变颜色返回。
关于java - 调用 LiveData onChanged() 方法时,ListAdapter 项目呈现不正确。 DiffUtil areContentsTheSame() 可能存在问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59814910/
这个问题已经有答案了: How to do case insensitive string comparison? (23 个回答) 已关闭 3 年前。 用户在我的输入栏中写入“足球”,然后执行第 6
啊,不习惯 javascript 中的字符串。 character_id= + id + correct= + correctOrIncorrect 这就是我需要制作成字符串的内容。如果您无法猜测字符
$(function() { var base_price = 0; CalculatePrice(); $(".math1").on('change', function(e) { Calc
我找不到任何文章回答问题:将Spinnaker部署到Spinnaker将管理的同一Kubernetes集群是否安全/正确?我主要是指生产,HA部署。 最佳答案 我认为Spinnaker和Kuberne
我正在使用MSVC在Windows上从源代码(官方源代码发布,而不是从仓库中)构建Qt5(Qt 5.15.0)。 我正在设置环境。变量,依赖项等,然后运行具有1600万个选项的configure,最后
我需要打印一个包含重复单词的数组。我的数组已经可以工作,但我不知道如何正确计算单词数。我已经知道,当我的索引计数器 (i) 为 49 时,并且当 (i) 想要计数到 50 时,我会收到错误,但我不知道
我正在遵循一个指南,该指南允许 Google map 屏幕根据屏幕尺寸禁用滚动。我唯一挣扎的部分是编写一个代码,当我手动调整屏幕大小时动态更改 True/False 值。 这是我按照说明操作的网站,但
我有一个类“FileButton”。它的目的是将文件链接到 JButton,FileButton 继承自 JButton。子类继承自此以使用链接到按钮的文件做有用的事情。 JingleCardButt
我的 friend 数组只返回一个数字而不是所有数字。 ($myfriends = 3) 应该是…… ($myfriends = 3 5 7 8 9 12). 如果我让它进入 while 循环……整个
这个问题在这里已经有了答案: Is there a workaround to make CSS classes with names that start with numbers valid?
我正在制作一个 JavaScript 函数,当调整窗口大小时,它会自动将 div 的大小调整为与窗口相同的宽度/高度。 该功能非常基本,但我注意到在调整窗口大小时出现明显的“绘制”滞后。在 JS fi
此问题的基本视觉效果可在 http://sevenx.de/demo/bootstrap-carousel/inc.carousel/tabbed-slider.html 获得。 - 如果你想看一看。
我明白,如果我想从函数返回一个字符串文字或一个数组,我应该将其声明为静态的,这样当被调用的函数被返回时,内容就不会“消亡”。 但我的问题是,当我在函数内部使用 malloc 分配内存时会怎样? 在下面
在 mySQL 数据库中存储 true/false/1/0 值最合适(读取数据消耗最少)的数据字段是什么? 我以前使用过一个字符长的 tinyint,但我不确定它是否是最佳解决方案? 谢谢! 最佳答案
我想一次读取并处理CSV文件第一行中的条目(例如打印)。我假设使用Unix风格的\n换行符,没有条目长度超过255个字符,并且(现在)在EOF之前有一个换行符。这意味着它是fgets()后跟strto
所以,我们都知道 -1 > 2u == true 的 C/C++ 有符号/无符号比较规则,并且我有一种情况,我想有效地实现“正确”比较。 我的问题是,考虑到人们熟悉的尽可能多的架构,哪种方法更有效。显
**摘要:**文章的标题看似自相矛盾。 本文分享自华为云社区《Java异常处理:如何写出“正确”但被编译器认为有语法错误的程序》,作者: Jerry Wang 。 文章的标题看似自相矛盾,然而我在“正
我有一个数据框,看起来像: dataDemo % mutate_each(funs(ifelse(. == '.', REF, as.character(.))), -POS) # POS REF
有人可以帮助我使用 VBScript 重新格式化/正确格式化带分隔符的文本文件吗? 我有一个文本文件 ^分界如下: AGREE^NAME^ADD1^ADD2^ADD3^ADD4^PCODE^BAL^A
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我是一名优秀的程序员,十分优秀!