简体   繁体   English

notifyDataSetChanged()没有调用onBindViewHolder

[英]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.

相关问题 每次调用 notifyDataSetChanged() 时,都会调用 onBindViewHolder() - Every time notifyDataSetChanged() is called, onBindViewHolder() is called notifyDataSetChanged()不调用onBindViewHolder()方法 - notifyDataSetChanged() doesn't call's onBindViewHolder() method Recycler View 不调用 onBindviewHolder - Recycler View not calling onBindviewHolder 调用notifyDataSetChanged()引发异常 - Calling notifyDataSetChanged() throws exception 从内部适配器调用notifyDataSetChanged失败 - Calling notifyDataSetChanged from inside adapter fails 调用notifyDataSetChanged()后丢失EditText值; - Losing EditText Value After Calling notifyDataSetChanged(); 快速滚动并在onBindViewHolder上调用API后,RecyclerView崩溃 - RecyclerView is crashing after fast scrolling and calling API onBindViewHolder 在CustomAdapter中调用BaseAdapter的notifyDataSetChanged()不会刷新ListView - calling BaseAdapter's notifyDataSetChanged() inside CustomAdapter not refreshing ListView 应用程序的PagerAdapter更改了适配器的内容,而无需调用notifyDataSetChanged() - Application's PagerAdapter changed the adapter's contents without calling notifyDataSetChanged() 调用notifydatasetchanged()之后,在Recyclerview中保持视图状态不变 - Keeping state of a view constant in Recyclerview after calling notifydatasetchanged()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM