我准备在recyclerView中实现recyclerView,最后我发现我可以将它实现为支持RecyclerViews的LinearLayout。
RecyclerView rv = new RecyclerView(this);
rv.setLayoutParams(new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 3);
rv.setHasFixedSize(true);
rv.setLayoutManager(layoutManager);
rv.setAdapter(new Adapter(...));
hostLinearLayout.addView(rvSingleMonth);
现在我想同时将所有这些RecyclerView作为LinearLayout的子项通知。
if (llRootView != null) {
for (int idx = 0; idx < hostLinearLayout.getChildCount(); idx++) {
try {
RecyclerView currentRv = (RecyclerView) hostLinearLayout.getChildAt(idx);
currentRv.getAdapter().notifyDataSetChanged();
} catch (Exception e){
}
}
}
但它确实无效! anyOne可以帮助我吗?
修改
by&#34;它确实起作用&#34;,我的意思是当我尝试通知recyclelerView(作为hostLinearLayout的子节点)时,如上所示,
RecyclerView currentRv = (RecyclerView) hostLinearLayout.getChildAt(idx);
currentRv.getAdapter().notifyDataSetChanged();
通知不会应用更改而且会使应用程序滞后。