You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by treponema <tr...@orange.fr> on 2012/08/13 18:26:44 UTC
How to set ListView data binding?
Hi,
I did not found how to bind a ListView to an ArrayList (although I found samples about TableViews). If I use setListData with an ArrayList, the strings are displayed, but if the class has more properties, can someone explains me how to tell the ListView which one to display, which one is the key?
Thanks...
P.S. : For instance: A list of person objects (properties: id, name, age, ...), I would like the ListView to display the name and return the id of the selected person.
Re: How to set ListView data binding?
Posted by treponema <tr...@orange.fr>.
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 : user@pivot.apache.org
> 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
> >
> >
>
>
Re: How to set ListView data binding?
Posted by Roger Whitcomb <Ro...@rbwhitcomb.com>.
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<Person> 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
>
>
Re: How to set ListView data binding?
Posted by Greg Brown <gk...@verizon.net>.
> 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
Re: How to set ListView data binding?
Posted by Sandro Martini <sa...@gmail.com>.
Hi,
> Thanks for the links, but I had already read twice all of them.
Ok, just to be sure :-) ...
> 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 ? I thought I could set the property to display with setListDataKey, but I do not understand how to do that.
I'm sorry but I haven't a sample of this (maybe Roger or others have),
so I have to write a minimal sample for it (could be useful for others
too).
Initial approach (even for me, to remember what to do):
copy some classes from
tutorials/org.apache.pivot.tutorials.databinding.* into
tests/org.apache.pivot.tests.* and see what happens trying to set
setListDataKey on a property of bean for the binding, maybe using
BeanAdapter ... all this just as general idea.
Just found something that could give some info on this:
org.apache.pivot.tests.DataBindingTest , under the tests subproject.
In the meantime, try to look at it ...
Let's update.
Bye,
Sandro
Re: How to set ListView data binding?
Posted by treponema <tr...@orange.fr>.
Hi,
Thanks for the links, but I had already read twice all of them.
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 ? I thought I could set the property to display with setListDataKey, but I do not understand how to do that.
Bye...
> Message du 14/08/12 11:48
> De : "Sandro Martini"
> A : user@pivot.apache.org
> Copie à :
> Objet : Re: How to set ListView data binding?
>
> Hi,
> this is a useful thing to show, but currently we don't have a small
> sample of it ...
>
> Did you tried with manual binding ?
> See here: http://pivot.apache.org/tutorials/property-binding.html
>
> and then maybe even:
> http://pivot.apache.org/tutorials/data-binding.html
> http://pivot.apache.org/tutorials/stock-tracker.data-binding.html
>
> Keep us updated.
>
> Bye,
> Sandro
>
Re: How to set ListView data binding?
Posted by Sandro Martini <sa...@gmail.com>.
Hi,
this is a useful thing to show, but currently we don't have a small
sample of it ...
Did you tried with manual binding ?
See here: http://pivot.apache.org/tutorials/property-binding.html
and then maybe even:
http://pivot.apache.org/tutorials/data-binding.html
http://pivot.apache.org/tutorials/stock-tracker.data-binding.html
Keep us updated.
Bye,
Sandro
re: How to set ListView data binding?
Posted by treponema <tr...@orange.fr>.
I just realized that something has removed the types of the ArrayLists from my message. For the first sentence it was Something, for the second it was String.
> Message du 13/08/12 18:27
> De : "treponema"
> A : user@pivot.apache.org
> Copie à :
> Objet : How to set ListView data binding?
>
> Hi,
> I did not found how to bind a ListView to an ArrayList (although I found samples about TableViews). If I use setListData with an ArrayList, the strings are displayed, but if the class has more properties, can someone explains me how to tell the ListView which one to display, which one is the key?
> Thanks...
>
> P.S. : For instance: A list of person objects (properties: id, name, age, ...), I would like the ListView to display the name and return the id of the selected person.
>