Thank you all,
I have written a custom list item renderer like this one:
listView.setItemRenderer(new ListViewItemRenderer() {
@Override
public void render(Object item, int index, ListView listView, boolean selected,
boolean checked, boolean highlighted, boolean disabled) {
if (item != null) {
item = ((Person) item).getName();
}
super.render(item, index, listView, selected, checked, highlighted, disabled);
}
@Override
public String toString(Object item) {
return ((Person) item).getName();
}
});
It is working fine.
Bye...
> Message du 14/08/12 19:25
> De : "Roger Whitcomb"
> A : [email protected]
> Copie à :
> Objet : Re: How to set ListView data binding?
>
> What I was thinking is that if your Person object's "toString" method returns
> whatever you want to display in the ListView. Then just use List as the
> ListView data. Then the "getSelectedItem" can return your Person object and
> you can do whatever you want with it.....
>
> HTH,
> ~Roger
>
> On Aug 14, 2012, at 9:39 AM, Greg Brown wrote:
>
> >> If I have an ArryList of person objects, is the only way to display their
> >> names in a ListView to create an ArrayList of Strings filled with their
> >> names and pass it to setListData ?
> >
> > You can use a custom list item renderer for this. See this example:
> >
> > http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/rss/
> >
> >> I thought I could set the property to display with setListDataKey, but I
> >> do not understand how to do that.
> >
> > This method sets the name of the key that is used in context binding (i.e.
> > load() and store()), so this is probably not what you want.
> >
> > Greg
> >
> >
>
>