我正在删除并根据需要添加相同的列表项并更新视图。我知道在添加新元素时我应该使用notifyItemInserted()
。当我有较少的列表项时,它会更新,但是当有更多项时,不会发生任何更改。无法理解这一点。帮助将不胜感激!
@OnClick(R.id.checkbox_physical_inventory)
void includeZeroInventoryItems() {
mItems.clear();
if (!mZeroInventoryCheckBox.isChecked()) {
mItems.addAll(queryListItems(false));
} else {
mItems.addAll(queryListItems(true));
}
setAdapter(mItems);
}
这是适配器:
private void setAdapter(List<Item> items) {
if (items != null && mPhysicalInventoryAdapter == null) {
mPhysicalInventoryAdapter = new PhysicalInventoryAdapter(getContext(), items);
mRecyclerView.setAdapter(mPhysicalInventoryAdapter);
} else if (mPhysicalInventoryAdapter != null) {
mPhysicalInventoryAdapter.notifyDataSetChanged();
}
}