I am using the ComboBox in LWUIT.
My code goes like this.
public Locations(String name, int X, int Y)
{
Name = name;
xLocation = X;
yLocation = Y;
}
I have made a list of Locations
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;
}
Then made the ComboBox contain the List.
comboBox_Locations = new ComboBox(getLocations().getModel());
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:
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;
}
But when I get the selectedItem, it only gets the Name and I cannot get the coordinates.
What I wanted to do is to get the class like this:
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();
}
So that I can use the xCoords and yCoords.
Use a renderer: