PDA

View Full Version : How to highlight item from combobox's listview



anttihavanko
9 Apr 2011, 11:33 PM
I have combobox which uses loader to query values from server. When data is loaded, I wan't to highlight/select the first item from combobox's listview and not the one which matches user's query.

So if user types 'car' and server returns 'bike' and 'car', it now highlights 'car' (and scrolls listview if item isn't visible). How to select 'bike' item so listview wouldn't scroll?

I tried to add listener to loader's 'load' event but no success.


loader.addListener(Loader.Load, new Listener<LoadEvent>() {
public void handleEvent(LoadEvent be) {
combo.select(0);
}
});

anttihavanko
12 Apr 2011, 4:57 AM
Here's one solution if someone has the same problem.

I override combobox's selectByValue method, and now it always selects first item on list. If someone knows better solution, please tell me.


final ComboBox<Model> combo = new ComboBox<Model>() {
@Override
protected boolean selectByValue(String value) {
if(getStore().getCount() > 0) {
select(0);
return true;
}
else
return false;
}
};