java - recyclerview内的嵌套cardview渲染房间问题
问题描述
在房间内的 RecylerView 中使用嵌套的 CardView 会导致 CardView 不会被呈现,直到您随后向下滚动并在包含的 RecylerView 中向上滚动。然后子 CardView 按预期显示。
这是我在父级别中的 BindView 持有者,它使用其数据调用子级别适配器。我假设这是因为数据是从线程中获取的,因此父级没有为 CardView 呈现空间的信息 - 但我不知道该怎么做。
@Override
public void onBindViewHolder(ItemViewHolder holder, int position) {
category current = myCategoryItems.get(position);
holder.textViewName.setText(current.Category);
//Set sub adapter
myAdapter = new SubCategoryCardAdapter(holder.subRecyclerView.getContext(),myFcontext);
holder.subRecyclerView.setAdapter(myAdapter);
holder.subRecyclerView.setLayoutManager(new LinearLayoutManager(holder.subRecyclerView.getContext(), RecyclerView.HORIZONTAL, false));
holder.subRecyclerView.setHasFixedSize(true);
mySubCategoryModel = new ViewModelProvider(myFcontext).get(SubCategoryModel.class);
//Update view when data changes - triggered by observer
mySubCategoryModel.getItemListByCat(current.cat_id).observe(myFcontext, sub_categoryList ->
myAdapter.setItems(sub_categoryList,this));
}
提前致谢。
code
公共类 SubCategoryRepository {
private SubCategoryDao mySubCategoryDao;
private LiveData<List<sub_category>> itemsList;
private LiveData<List<sub_category>> itemsListByCat;
SubCategoryRepository(Application application) {
KaitkanDatabase database = KaitkanDatabase.getDatabase(application);
mySubCategoryDao = database.sub_categoryDao();
itemsList = mySubCategoryDao.getItemList();
}
LiveData<List<sub_category>> getAllItems() {
return itemsList;
}
LiveData<List<sub_category>> getItemListByCat( Integer catid) {
itemsListByCat = mySubCategoryDao.getItemListByCat(catid);
return itemsListByCat;
}
} 公共类 SubCategoryModel 扩展 AndroidViewModel {
private SubCategoryRepository mySubCategoryRepository;
private LiveData<List<sub_category>> allItems;
private LiveData<List<sub_category>> itemsForCat;
public SubCategoryModel(Application application) {
super(application);
mySubCategoryRepository = new SubCategoryRepository(application);
allItems = mySubCategoryRepository.getAllItems(); //gets the data as list from DB
}
public LiveData<List<sub_category>> getAllItems()
{ return allItems; }
public LiveData<List<sub_category>> getItemListByCat(Integer catid)
{ itemsForCat = mySubCategoryRepository.getItemListByCat(catid);
return itemsForCat; }
}
解决方案
推荐阅读
- python - Panda3D:TypeError:run() 缺少 1 个必需的位置参数:'self'
- javascript - WebHID API:断开连接事件未触发
- python - 我需要设置一个 HTML 代码来接收来自 python 的 requests.post HTTP 请求
- python - 分类交叉熵?
- python - 如何通过python在excel文件中添加一列结果?
- pandas - 在依赖于前一行值的 DataFrame 上应用函数
- javascript - 页面更新后 eventListener 没有运行
- reactjs - 如何将动态对象数组的类型声明为反应状态?
- aem - 绑定到资源类型 OSGi R6 注释的 Sling servlet 不起作用
- c# - ASP.NET Core MVC 列表
.包含(模型)