entry : alacc.respo" />

Setting values to each comboBox item

codenameone

364 просмотра

1 ответ

populate combobox code:

ComboBox getCategoryComboBox = new ComboBox();
searchOptionForm.add(getCategoryComboBox);

getCategoryComboBox.setUIID("TextField");
getCategoryComboBox.addItem("Choose Category");

for (Map<String, Object> entry : alacc.responseCategory) {
    String categoryName = (String) entry.get("name");
    String categoryId = (String) entry.get("id");//how to set this to combobox item
    getCategoryComboBox.addItem(categoryName);
}

categoryId is taken from for loop above, how to set it in each combobox items? I need to get the categoryId of each selected combobox item, how can i get this?

Автор: Amrita Stha Источник Размещён: 08.11.2019 11:00

Ответы (1)


0 плюса

You have several ways to do this.

One way is to just do:

getCategoryComboBox.addItem(entry);

Which would provide you the full entry on getSelectedItem() effectively solving that problem.

To make the name render properly though you would need to do this:

cb.setRenderer(new DefaultListCellRenderer<Object>() {
   public Component getCellRendererComponent(Component list, Object model, Object value, int index, boolean isSelected) {
      if(value instanceof Map) {
         value = ((Map)value).get("name");
      }
      return super.getCellRendererComponent(list, model, value, index, isSelected);
   }
});

Notice you will also need to define the theme constant otherPopupRendererBool to false for this to work properly.

Автор: Shai Almog Размещён: 21.08.2016 05:24
Вопросы из категории :
32x32