Get the selected widget in a list

2009-02-11 17:13
Submit by Tofu

Kuix manage Lists as a normal tree of widgets. In this case there no special way to know which item index of a list is selected. But you can retrieve the focused widget (which is the selected one). And if you build you list from a DataProvider, each ListItem has a reference to it corresponding data source, then you would be able to know the selected element in your model.

For the next example we suposed that our list is filled by a dataprovider the respond to the contacts property and deliver a set of Dataprovider that responds to the name property.

XML file :

<screen>

<list id="mylist">

<_renderer><![CDATA[

<listitem>${name}</listitem>

</_renderer>

<_items>@{contacts}</_items>

</list>

<screenfirstmenu onAction="show(#mylist.focusedwidget.dataprovider)">Show</screenfirstmenu>

</screen>

Java file : (a class that represent the current frame)

public boolean onMessage(Object identifier, Object[] argument) {

if ("show".equals(identifier) {

Contact selectedContact = (Contact) arguments[0];

System.out.println(contact.name);

return false;

}

return true;

}

 

Java file : (the Contact dataProvider)

public class Contact extends DataProvider {

public name;

public String getUserDefinedValue(String property) {

if ("name".equals(property)) {

return name;

}

return null;

}

}


Tags: list selected Popularity: 1067