I’m trying to properly use a dropdown, but am not able to get the individual dropdown item, and also am not understanding some parts.
My main.xml (patterned after component-examples demo/basic.xml) looks like:
<vbox style="padding: 5px;" width="100%" height="100%">
<dropdown id="dropDown1" text="Select" width="100%">
<data>
<item id="dd1i1" value="Item 1" />
<item id="dd1i2" value="Item 2" />
<item id="dd1i3" value="Item 3" />
<item id="dd1i4" value="Item 4" />
<item id="dd1i5" value="Item 5" />
<item id="dd1i6" value="Item 6" />
</data>
</dropdown>
</vbox>
(“dd1i1” == “dropdown-1 item-1”, and so on.)
In Main.hx I import haxe.ui.components.DropDown;
, and in my Main.main function I grab the event and set the handler with:
var dd1 = main.findComponent("dropDown1", DropDown);
dd1.onChange = handleDropDown1;
It seems to work. For the handleDropDown1
function I’ve got:
public static function handleDropDown1(e) {
var dd = cast(e.target, DropDown);
trace('${dd}, ${dd.id}, ${dd.selectedIndex}');
}
and when I build and run the app it starts out blank (no choice selected):
When with the dropdown, I choose item 1, item 2, then item 3 (only once each), and it prints out:
src/Main.hx:34: DropDown, dropDown1, 0
src/Main.hx:34: DropDown, dropDown1, 0
src/Main.hx:34: DropDown, dropDown1, 1
src/Main.hx:34: DropDown, dropDown1, 1
src/Main.hx:34: DropDown, dropDown1, 2
src/Main.hx:34: DropDown, dropDown1, 2
My questions are:
-
How do I choose one of the items in the dropdown to be initially selected when the app starts?
-
In the main.xml
<dropdown
tag, what would I use thetext="Select"
for? I don’t see it in my GUI anywhere. -
Why does the trace in
handleDropDown1()
print out twice for each single time I select
an item in the dropdown? -
How do I get at the individual dropdown item’s (id’s “dd1i1”, “dd1i2”, etc.)? Or, maybe I don’t even need to assign and use them if I have the
.selectedIndex
's?
Any other feedback on how the above looks is much appreciated as well!
By the way, I don’t see the docs for DropDown at http://haxeui.github.io/haxeui-api/.
Thanks!