RecyclerView, GridLayoutManager and dynamic Spans count

…衆ロ難τιáo~ 提交于 2019-12-06 14:05:24

Actually I solved the problem. I noticed the setSpanSizeLookup method was called only after notifyItemInserted. I have to put my resizes method after.

public void add(Schedule item) {
    Integer nbHour = schedulesToDisplay.get(item.hour);
    int position = mDataset.size();
    if(nbHour == null){
        schedulesToDisplay.put(item.hour, 1);
        Log.d(item.toString()+" : 1 span ("+position+")", TAG);
    }
    else{
        nbHour++;
        schedulesToDisplay.put(item.hour, nbHour);
        Log.d(item.toString()+ " : " + nbHour +" spans ("+position+")", TAG);
        if(nbHour > maxSpans){
            maxSpans = nbHour;
        }
    }
    mDataset.add(position, item);
    notifyItemInserted(position);

    layoutManager.setSpanCount(maxSpans);
    layoutManager.requestLayout();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!