Note that there are some explanatory texts on larger screens.

plurals
  1. POLWUIT ComboBox: Class as the Items
    primarykey
    data
    text
    <p>I am using the <code>ComboBox</code> in LWUIT. My code goes like this.</p> <pre><code>public Locations(String name, int X, int Y) { Name = name; xLocation = X; yLocation = Y; } </code></pre> <p>I have made a list of <code>Locations</code></p> <pre><code>private List getLocations() { List list = new List(); list.addItem(new Locations("Landmark1", 23, 40)); list.addItem(new Locations("Landmark3", 24, 40)); list.addItem(new Locations("Landmark4", 25, 40)); list.addItem(new Locations("Landmark6", 26, 40)); return list; } </code></pre> <p>Then made the ComboBox contain the List.</p> <pre><code>comboBox_Locations = new ComboBox(getLocations().getModel()); </code></pre> <p>Now, my problem is that how can I display only the Name of the Location on the ComboBox? I know I can make a list of strings of the Name of the Location like this: </p> <pre><code>private List getLocations() { List list = new List(); list.addItem(new Locations("Landmark1", 23, 40).Name); list.addItem(new Locations("Landmark3", 24, 40).Name); list.addItem(new Locations("Landmark4", 25, 40).Name); list.addItem(new Locations("Landmark6", 26, 40).Name); return list; } </code></pre> <p>But when I get the <code>selectedItem</code>, it only gets the Name and I cannot get the coordinates. What I wanted to do is to get the class like this: </p> <pre><code>Object item = comboBox_Locations.getSelectedItem(); if (item.getClass() == Locations.class) { String Name = ((Locations)item).Name.toString(); int xCoords = ((Locations)item).getX(); int yCoords = ((Locations)item).getY(); } </code></pre> <p>So that I can use the xCoords and yCoords.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload