Reputation: 6249
I tried two PickerComponents inside a TextModeLayout with the simulator (with an Android skin). I don't like that a PickerComponent of Strings shows three dots on unselected state. I also don't like that the PickerComponent of a Date shows the today date. In both cases, I want to show a custom text, also because I don't want a default selected value. For example, if I want to pick the date of birth, I don't feel that it makes sense to preset the today date.
After a lot of trials, I tried to solve this issue with the following code, but I'm not sure if it's a correct way. My question is what is the best approch in a portable manner (that is ok for Android and for iOS):
/**
* Set a custom text for an unselected PickerComponent placed in a
* TextModeLayout
*
* @param picker
* @param text
*/
private void pickerComponentSetUnselectedText(PickerComponent picker, String text) {
picker.getPicker().setText(text);
picker.getPicker().setUIID("TextHint");
picker.getPicker().addActionListener(l -> {
l.getComponent().setUIID("TextField");
});
}
I tried to use that method so:
TextModeLayout textModeLayout = new TextModeLayout(4, 1);
Container inputPersonData = new Container(textModeLayout);
TextComponent name = new TextComponent().label("Nome");
TextComponent surname = new TextComponent().label("Cognome");
PickerComponent gender = PickerComponent.createStrings("Maschio", "Femmina", "altro").label("Genere");
PickerComponent date = PickerComponent.createDate(new Date()).label("Data di nascita");
inputPersonData.add(name);
inputPersonData.add(surname);
inputPersonData.add(gender);
inputPersonData.add(date);
pickerComponentSetUnselectedText(gender, "Genere");
pickerComponentSetUnselectedText(date, "Data di nascita");
Upvotes: 1
Views: 34
Reputation: 52760
The picker component has two pieces, the one with the text isn't native but the popup is (and that's the source of most of the problems).
If what you did worked go with it. Historically we would recommend subclassing picker and overriding updateValue
but it's impossible to do with PickerComponent
so I added a new method which should be available in the next update:
PickerComponent cmp = new PickerComponent() {
protected Picker createPickerInstance() {
return new Picker() {
protected void updateValue() {
// place your logic here.. and invoke setText(...);
}
};
}
};
Upvotes: 1