[英]notifyDataSetChanged() is not calling onBindViewHolder
When i call notifyDataSetChanged() it doesn't call my onBindViewHolder and i have no idea why it does this, i am currely using a custom layout and don't know if that has anything to do with it. 当我调用notifyDataSetChanged()时,它不会调用我的onBindViewHolder,我也不知道为什么这样做,我正在使用自定义布局,并且不知道是否与此有关。
Anybody have any ideas? 有人有什么想法吗? here is the code is the peace of code I use to call the datasetchange within my adapter. 这是代码,我在适配器内调用数据集更改时使用的代码是和平的。
public void updateFriendsCheckinData(HashMap<Integer, List<LiveCheckin>> updatedCheckinMap){
this.friendCheckinMap = updatedCheckinMap;
notifyDataSetChanged();
}
try this: 尝试这个:
public void updateFriendsCheckinData(HashMap<Integer, List<LiveCheckin>> updatedCheckinMap) {
// here we are clearing existing data in the HashMap
friendCheckinMap.clear();
friendCheckinMap = updatedCheckinMap;
notifyDataSetChanged();
}
And then in your getItemCount() method we have: 然后在您的getItemCount()方法中,我们有:
@Override
public int getItemCount() {
// if you are using the data in the list retrieved from the hashmap, then here return the size of the list instead.
return friendCheckinMap.size();
}
Hope this helps. 希望这可以帮助。
You've to call notifydatasetchanged in onClick events instead of OnBindviewHolder. 您必须在onClick事件而不是OnBindviewHolder中调用notifydatasetchanged。
if you call on OnBindviewHolder it might crash due to recyclerview populating views. 如果调用OnBindviewHolder,则可能由于recyclerview填充视图而崩溃。
Here is the samplecode 这是示例代码
@Override
public void onRecyclerViewItemClick(@NonNull View view, @NonNull AndroidVersion calendarDTO, int position) {
Toast.makeText(getContext(),String.valueOf(position), Toast.LENGTH_SHORT).show();
adapter.notifyDataSetChanged();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.