【问题标题】:Codename One toolbar repopulate (refresh?) sidemenu代号一个工具栏重新填充(刷新?)侧边菜单
【发布时间】:2018-06-10 05:30:00
【问题描述】:

我有一个应用程序,它使用来自 ArrayList (listOne) 的输入来创建组件条目。

在某一时刻,我想用第二个 ArrayList(listTwo,实际上是对 listOne 的修改)中的元素重新填充侧边菜单。

我的问题是两个列表中的项目都出现在侧面菜单中。

如何刷新侧边菜单,让它只显示新列表的项目?

我们将不胜感激。

这是我目前所拥有的:

tb = hi.getToolbar();

for (String s : listOne) {
    testLabel = new Label(s);
    tb.addComponentToSideMenu(testLabel);
}


public void test () {

    tb.remove();
    tb.removeAll();
    tb.removeComponent(testLabel);
    testLabel.remove();

    for (String string : listTwo) {
        testLabel = new Label(string);
        tb.addComponentToSideMenu(testLabel);
    }

}

【问题讨论】:

  • 不建议使用 tb.remove()tb.removeAll() 之类的东西,因为您正在入侵我们内部的工具栏实现。

标签: codenameone side-menu


【解决方案1】:

我找到了一种方法来做到这一点,但我不知道它是否理想:

c = new Container();
c.setLayout(new BoxLayout(2));

for (String s : listOne) {
     c.add(new Label("test"));
}
tb.addComponentToSideMenu(c);


public void test () {

    c.remove(); 

    c = new Container();
    c.setLayout(new BoxLayout(2));

    for (String s : listTwo) {
        c.add(new Label("test 2"));
    }

    tb.addComponentToSideMenu(c);
}

【讨论】:

  • 我建议只做 c.removeAll() 然后在 c 中添加新条目,而不是从父容器中删除容器并再次添加。
猜你喜欢
  • 2020-08-14
  • 2018-03-29
  • 1970-01-01
  • 2017-12-25
  • 1970-01-01
  • 1970-01-01
  • 2012-05-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多