tabris
tabris copied to clipboard
Android Tabris 1.2 dropdown Combo cannot have no selection
Not sure if this is deliberate, but on Android is it impossible to have a Combo dropdown that doesn't have a value selected (assuming there are values to choose from).
All other platforms, if I don't do a .setText() on the Combo, it remains blank until I select something, but on Android it always defaults to the first item in the list.
Snippet below.
/* DEMONSTRATES TABRIS PROBLEM WITH COMBOS WITH NO VALUE ON ANDROID*/ package bug.snippet;
import java.util.ArrayList; import java.util.List;
import org.eclipse.rap.rwt.service.ServerPushSession; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell;
public class Bugsy { private Display display; private Shell shell; private Combo combo; private List<String> comboValueList;
public void begin() {
System.out.println("BugSnippy Starting...");
// create the Shell
display = new Display();
shell = new Shell(display, SWT.NONE);
shell.setText("Shell");
shell.setFullScreen(true);
shell.setBackground(new Color(null, new RGB(255,255,192)));
FormLayout layout = new FormLayout();
shell.setLayout(layout);
FormData fd;
//create the Combo
combo = new Combo(shell, SWT.DROP_DOWN);
//set Combo's position
fd = new FormData();
fd.left = new FormAttachment(0, 10);
fd.top = new FormAttachment(0, 50);
fd.right = new FormAttachment(0, 200);
//fd.bottom = new FormAttachment(100,-10);
combo.setLayoutData(fd);
combo.addListener(SWT.Selection, listener);
final ServerPushSession pushSession = new ServerPushSession();
pushSession.start();
comboValueList = new ArrayList<String>();
comboValueList.clear();
comboValueList.add("item1");
comboValueList.add("item2");
comboValueList.add("item3");
combo.setItems((String[]) comboValueList.toArray(new String[comboValueList.size()]));
shell.open();
System.out.println("BugSnippy Done!");
}
Listener listener = new Listener() {
public void handleEvent(Event event) {
int i = combo.getSelectionIndex();
String s = combo.getItem(i);
System.out.println("SELECTED: " + s);
}
};
}
The described behavior is the default for Android. You can not have an empty selection in Combo widgets. Do circumvent that we would have to rewrite the widget from scratch. It could be done but would require some effort.
Hmm, seems like an odd behaviour for Android to have as normal. Ok, though, if that's the way they enforce it, then that's what we'll have to live with. Thanks, John