Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
dresslerc
Posts: 15
Registered: ‎10-15-2008
My Device: Not Specified

BlackBerry SDK 7 Beta RichList setCommand

Hello,

 

I am using a RichList to display some data.  I now want to know when someone clicks on an item.  To do this I created a class that Implements CommandHandler that overrides the execute method.  Here I am displaying a Dialog box that on what the context object has.

 

The event fires but the context object is null and so is the metadata.  I Googled some more and found that I can set the CommandContext on the RichList.  Doing this now populates the context when something is clicked but it still has no data from the actual item in the RichList. 

 

How do you properly implement the setCommand on a RichList?

 

Carsten

Please use plain text.
Contributor
dresslerc
Posts: 15
Registered: ‎10-15-2008
My Device: Not Specified

Re: BlackBerry SDK 7 Beta RichList setCommand

I got it working.  Just wanted to share with the community incase someone else has the same question.

 

First you create a class that extends CommandHandler.  Then you override the execute method with your logic:

 

public class RichListCH extends CommandHandler {

public void execute(ReadOnlyCommandMetadata metadata, Object context) {

 

RichList rl = (RichList) context;

Object[] items = rl.get(rl.getFocusRow());

 

//Do something where with your Object

}

}

 

When you setup your RichList you do the following:

 

        list.setCommand(new Command(new RichListCH()));       

list.setCommandContext(list);

 

The first line tells the system to fire the Execute method in the CommandHandler.  The 2nd line basically will pass the existing List to the CommandHandler so you can read the data.

 

Not sure if this is the proper way to implement this, but the documentation currently out there is a mess. 

 

Hope this helps.

 

Carsten

 

Please use plain text.