Il 02/08/2010 18:47, Alejandro Vilar ha scritto:
Hi Stefano,
Hi Alejandro, thanks for your prompt replay.
Your approach works well because "toString" method only be called when a customer is painted, but it doesn't avoids some possible side effects in the rest of your code(i.e. logging). Another way is to use renderers as follows:
<snip> Ok an other subject to learn: renderers
Also you can keep the computed name inside a variable in your lbtCustomer instance to compute it just once. To setup this renderer in your ListButton:ListButton listButton = new ListButton(customers); listButton.setDataRenderer(new CustomerDataRenderer());listButton.setItemRenderer(new CustomerItemRenderer()); //<-- same as data renderer, but extending from ListViewItemRenderer
If I use both DataRenderer and ItemRenderer I guess - a wild guess - that the DataRenderer will compute name + " - " + address the first time the listButton is initialized and then the ItemRenderer will return the value to show to the user every time he scrolls the list.
If you want get the chosen record:lbtCutomer selectedCustomer = (lbtCutomer)listButton.getSelectedItem();
Ok, so you don't see any problem associated with the instantiation of 1000 objects.
I'll suggest override equals method in your lbtCustomer class, some list abilities are based on it.
Ok.
Hope this helps,
Absolutely, thanks again. Stefano
Alejandro
-- Dr. Stefano Sancese WatchGuard Certified System Professional - http://www.watchguard.com Socio Clusit - Associazione Italiana per la Sicurezza Informatica ************************************************************************ In God we trust, all others we monitor (National Security Agency) ************************************************************************
smime.p7s
Description: S/MIME Cryptographic Signature
