08-02-2009 02:52 PM - edited 08-02-2009 02:53 PM
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.
Solved! Go to Solution.
08-03-2009 02:29 AM
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.
Let me know if you have any problem with this!
08-07-2009 11:34 PM - edited 08-08-2009 02:44 AM
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.
08-08-2009 09:56 AM
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.