Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
类Foo有一个变量List<Button> bar,如何使用 UiBinder 渲染每个按钮?甚至可能吗?
Foo
List<Button> bar
UiBinder 是一个用于声明式布局小部件的 XML模板,它不是渲染器。因此,在 UiBinder XML 中不能有条件、循环和其他逻辑结构。
相反,您可以做的是在 UiBinder 中有一个面板作为您希望所有按钮去的地方的占位符。在您的 Java 类中有一个对此面板的 ui:field 引用。使用字段句柄循环遍历按钮列表并将按钮添加到 java 代码中的面板。
其他方法是定义一个组合并将组合添加到 UiBinder 中,并让组合自己完成按钮的呈现。只取决于最适合您的设计。