Reputation: 23
Do pickers only works with strings? It's not possible to use a generic class overriding the method toString?
I use this technique in Java with ComboBox. For example, if a user must choose a employee I create a class with two parameters int code
and String name
and a method toString()
and populate the ComboBox with objects from that class. The user chooses seeing the names and I can get the code of chosen employee casting the getSelectedItem()
to the class created.
Upvotes: 0
Views: 290
Reputation: 52770
Pickers map to OS native calls which provide deep native integration with the OS e.g. a time picker on Android looks like this:
So Picker effectively supports time, date, numbers or Strings as anything more elaborate can't be expressed natively in a reasonable way.
You can use the ComboBox
class which is pretty similar to what Swing has and has it's own renderer but it might feel unnatural on the device. Personally I would just use a button and show a popup Dialog
when it's pressed if you need customizable capabilities.
Upvotes: 0