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
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550
Accepted Solution

How to detect when ObjectListField selected item has changed?

[ Edited ]

I have extended ObjectListField to implement a iPod-style marquee scroller for long lines of text that go off the screen. So far I have everything working fine, and it functions as I would expect.... when it fires.

 

I'm having a problem finding a way to reliably make it activate. There does not seem to be any method I can override or any listener I can use that will fire when the selected item of the listview is changed. First I tried overriding setSelectedIndex. That only worked sometimes, since apparently the OS doesn't call setSelectedIndex when it wants to change the selected item, it does something else.

 

Next I tried overriding navigationMovement and manually calling the code to start the timer, but that didn't work either (I was overriding the ListField's navigationMovement method, maybe I should've done the manager's instead?). But either way this approach won't work for the Storm version of my app since the storm never calls navigationMovement.

 

Then I tried using a fieldChangeListener, but apparently that doesn't get fired for selection changes.

 

Finally in despiration I tried overriding drawListRow, only calling it when index was equal to the selectedRow. But my scrolling code calls invalidate, so of course it just results in a drawListRow infinite loop, slowing down the device and not even starting the scroller since each time the timer is started it cancels the old one.

 

Anyone have any ideas on what I can do here? Thanks.

Message Edited by Andiamo on 08-02-2009 02:53 PM
Please use plain text.
Developer
Mudassir
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified

Re: How to detect when ObjectListField selected item has changed?

Hi,

Try to override protected void fieldChangeNotify(int context). It will certainly work for you.

 

 

Thanks and Regards
Please use plain text.
Developer
jackofall
Posts: 120
Registered: ‎06-23-2009
My Device: Not Specified

Re: How to detect when ObjectListField selected item has changed?

               


You  need to set the ChangeListener first then  the method

protected void fieldChangeNotify(int context)

will be called automatically and as mudassir said you need to override that. 

                 

choice=new ObjectChoiceField("",choiceItems);

choice.setChangeListener(this);

this.add(choice);

 

Let me know if you have any problem with this!

Thanks & Regards

Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Please use plain text.
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550

Re: How to detect when ObjectListField selected item has changed?

[ Edited ]

Hi jackofall and Mudassir,

 

what is "this" referring to in that sample you posted? Not the screen, because the screen isn't the a changelistener type so it won't work there.

 

I am a little confused. Where am I setting the listener? For which object is the listener being created for (the objectlistfield or the screen itself)? Which fieldChangeNotify am I overriding (again, the OLF or the screen)?

 

Thanks for your help.

Message Edited by Andiamo on 08-08-2009 02:44 AM
Please use plain text.
Developer
Andiamo
Posts: 39
Registered: ‎05-26-2009
My Device: BlackBerry Storm 9550

Re: How to detect when ObjectListField selected item has changed?

Alright in the end I could not get fieldChangeNotify to fire, no matter which one I overrided, even with setting the listener first. It just does not seem to fire for the selection change event. One thing to note, I'm using an ObjectListField, not an ObjectChoiceField.... maybe you're both thinking of a different field?

 

Thanks for the help anyway, in the end I was able to get the desired effect by modifying the code slightly to reuse the same animation timer instead of creating a new one when the selected item is changed. The timer is started in the ListField's constructor. Works great.

Please use plain text.
New Contributor
Nagarjuna
Posts: 2
Registered: ‎01-29-2011
My Device: Not Specified
My Carrier: 9550 Simulator

Re: How to detect when ObjectListField selected item has changed?

Please submit that code

Please use plain text.