Android 带有SortedList的嵌套RecyclerView不显示任何内容
我在a中嵌套了一个,适配器使用a来保存内容 这是我的布局:Android 带有SortedList的嵌套RecyclerView不显示任何内容,android,android-recyclerview,sortedlist,Android,Android Recyclerview,Sortedlist,我在a中嵌套了一个,适配器使用a来保存内容 这是我的布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.widget.NestedScrollView
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
marginTop="@{StatusbarUtils.getTopMargin(context)}"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- some more ui elements -->
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_settings_cameras"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- some more ui elements -->
</android.support.v4.widget.NestedScrollView>
</FrameLayout>
当我使用它并调用addCamera(…)
时,什么都不会发生:-(
SortedListAdapterCallback
有一个onInserted
方法,它调用mAdapter.notifyItemRangeInserted(position,count)
。当我覆盖它并添加适配器时。notifyDataSetChanged()
回收视图显示项目
@Override
public void onInserted(int position, int count) {
Timber.i("onInserted() called with: " + "position = " + position + ", count = " + count);
adapter.notifyDataSetChanged();
super.onInserted(position, count);
}
这是一个bug还是我做错了什么?您需要删除
setHasFixedSize(true)
调用(默认值为false)。如果这是真的,则当您通知他时,recyclerview
认为其大小不会改变,但这里不是这样;)
希望这有帮助
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
linearLayoutManager.setAutoMeasureEnabled(true);
adapter = new SettingsRecyclerViewAdapter(this);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setAdapter(adapter);
@Override
public void onInserted(int position, int count) {
Timber.i("onInserted() called with: " + "position = " + position + ", count = " + count);
adapter.notifyDataSetChanged();
super.onInserted(position, count);
}