如何在notifydatasetchanged之后滚动时管理回收器视图中的位置

时间:2016-09-02 11:54:41

标签: android android-recyclerview android-adapter recycler-adapter

这是我的代码,我必须第一次调用方法 // Fifth Grade class teachers // var blower = L.marker([-38.68551, -44.12109], {icon: fiveTeacherIcon}).bindPopup('Mrs. Blower\'s class'), okonowski = L.marker([-55.47885, -43.41797], {icon: fiveTeacherIcon}).bindPopup('Mrs. Okonowski\'s class'), vermeulen = L.marker([-38.95941, -23.37891], {icon: fiveTeacherIcon}).bindPopup('Mrs. Vermeulen\'s class'); var fifthGrade = L.layerGroup([blower, okonowski, vermeulen]); var classesOverlay = { "Kindergarten": kindergarten, "First Grade": firstGrade, "Second Grade": secondGrade, "Third Grade": thirdGrade, "Fourth Grade": fourthGrade, "Fifth Grade": fifthGrade }; L.control.layers(classesOverlay).addTo(cmap); 才能在getServerResponse()中存储,当我向下滚动时,我必须调用方法arraylist。我得到了结果并通知适配器但是在向下滚动数据后更改位置或者可能不可见或者更改。我为聊天创建了自定义适配器。请帮我解决这个问题。

getServerResponseScroll()

1 个答案:

答案 0 :(得分:0)

来自onSaveInstanceState文档:

Called when the LayoutManager should save its state. This is a good time to save your
             * scroll position, configuration and anything else that may be required to restore the same
             * layout state if the LayoutManager is recreated.
             * RecyclerView does NOT verify if the LayoutManager has changed between state save and
             * restore. This will let you share information between your LayoutManagers but it is also
             * your responsibility to make sure they use the same parcelable class.

获取Recyclerview的当前状态:

private Parcelable recyclerViewState = recyclerView.getLayoutManager().onSaveInstanceState();

恢复已保存的实例:

recyclerView.getLayoutManager().onRestoreInstanceState(recyclerViewState);