09-03-2009 06:48 AM
I have a custom control called FileListField that inherits from ListField and represents a list of files in a directory of the file system. When you click on an item in the list and it is a directory, it goes to the new directory and lists the files in the new directory. However, when you click on a file, I want to raise an event that the encapsulating screen handles called something like FileSelected. Is this possible within the Blackberry Framework?
I have tried things like setting the instance of the list's FieldChangeListener to be handled in the screen, but the problem is that it gets called multiple times when a directory is selected and I don't want to have it fire at all in this case since a file wasn't selected. I really want to have more control so that when the event fires I can be sure that a file was selected. Can you create custom listeners and events? Is there some other event that I should plug in to?
Thank you in advance! This community is great!
09-03-2009 08:38 AM
09-04-2009 02:12 AM
What special support do you expect from the API?
If you have worked with Java before and know anything about the Observer/Observable design pattern, or more generic Listeners, then you can easily implement all yourself. There's no need for special API support.
Just pass your screen as the owner to the ListField via your constructor. That way the ListField has a reference to the screen. Then, whenever a user clicks on a file entry, you call whatever method you need on the screen from within the trackwheelClick() method after you determined that the selected entry in the list is a of type file.
09-04-2009 07:35 AM
I don't expect "special support". I stated that the package was limited. For example in the mobile version of java you can't use ArrayList. I know I can implement it myself, but I was just looking for a little support code. Observer/Observable got cut from this version of java too!
I don't want to pass in a hard reference to a screen in my generic control. I guess I will just have to make an interface and construct my own addListener in my observable class.
09-04-2009 07:38 AM
Instead of ArrayList you can use Vector, the grandfather of all List types in the collection framework introduced in Java 1.2
If you have ever used the Oberserver/Oberservable classes in Java, then you will know that they are limited in their use and it's easier to come up with a own implementation based on what you basically just said yourself: A generic listener interface and a add/removeListener() method.
All so easy... :-)