Best way to implement actions for SourceListItem s

4 views
Skip to first unread message

gurjeet

unread,
Jul 6, 2009, 2:19:54 AM7/6/09
to Mac Widgets for Java
Hi,

I am experimenting with the SourceList component for an application. I
just realized that the only way to implement action methods on the
individual SourceListItem s is the following:

1. Add a SourceListClickListener to the SourceList
2. Implement the sourceListItemClicked method
3. The method is called with a SourceListItem which got clicked on

Presumably one would have a HashTable with the keys being the
SourceListItems and the values being some object which implements the
function we want called when the item is clicked. Now, one looks up
the value object given the SourceListItem and call the function.

I was wondering if I got this right or not ? The reason I ask is that
I would have expected that one would simply be able to do something
like:

SouceListItem item = new SourceListItem("a");
item.addSourceListClickListener(
public void sourceListItemClicked(Button button, int clickCount)
{}
);

Now, whenever the item is clicked/interacted with, this method gets
called and one does not have to resort to a HashTable etc.

I would like to know the idea behind the former implementation instead
of the latter ?

Thanks,
Gurjeet

Ken Orr

unread,
Jul 6, 2009, 6:55:58 AM7/6/09
to mac-widget...@googlegroups.com
Hi Gureet,

You're instincts for what the API *should* look like are right on. In fact, you're not the first person to ask for ActionListeners on SourceListItems:


I plan to add a SourceListItem constructor that lets you pass in a listener that will be called when the item is selected.

-Ken
Reply all
Reply to author
Forward
0 new messages