简体   繁体   English

Recycler 视图中的表布局

[英]Table Layout inside Recycler view

design设计

This is a recycler view design which i am working on.. In this, under Additional Info, I need to display a table [field and value in each row] which updates along with other data when user scrolls down and sometimes this additional info column is empty.. I tried adding table layout, i am able to count how many fields are there and add them programmatically inside table as rows, but i am getting remove view(ie.table rows added using tabayout.addView(tablerow) method) error when user scrolls.. Are there any alternatives to this?这是我正在研究的回收器视图设计.. 在此,在附加信息下,我需要显示一个表 [每行中的字段和值],当用户向下滚动时,该表会与其他数据一起更新,有时还会显示此附加信息列是空的..我尝试添加表格布局,我能够计算有多少字段并以编程方式将它们添加到表格中作为行,但我正在删除视图(即使用 tabayout.addView(tablerow) 方法添加的表格行)用户滚动时出错.. 有没有其他选择? Or can i use some other way to implement this?或者我可以使用其他方式来实现这一点吗? Please help me..请帮我..

好吧,您可以为持有者设计单个布局,边框围绕该布局的父类,并将该布局放在适配器的 bindviewholder 中,该布局也被边框包围,使整个视图更加优雅

In onCreate with activity or in onCreateView with Fragment.在带有活动的 onCreate 或带有 Fragment 的 onCreateView 中。 You need to remove all the views before adding new view as below -您需要在添加新视图之前删除所有视图,如下所示 -

 (YourViewName.parent as? ViewGroup)?.removeView(YourViewName)

PS - This will work if you are using Kotlin. PS - 如果您使用 Kotlin,这将起作用。

Below code snippet is for Java -下面的代码片段适用于 Java -

if (view != null) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
       parent.removeView(view);
    } 
}
try {
    view = inflater.inflate(R.layout.YourFragmentName, container, false);
} catch (InflateException e) {
  // catch exception
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM