BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-18-2007, 10:56 AM   #1 (permalink)
New Member
 
Join Date: Aug 2007
Model: 7100T
PIN: N/A
Carrier: cingular
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting the selected index from a ChoiceField

Please Login to Remove!

Hi everyone, I ran into a problem that seems easy but I could not yet figure out how to solve. I have a ObjectChoiceField and a button. The visibility of the button should be determined based on the selected value of the ChoiceField. If the last item in the ChoiceField is selected, the button should not be visible. But as soon as the user changes the selection (from the last one to any other one), the button should be visible again. I figured that the easiest way to do this is to implement a FieldChangeListener on the ChoiceField and when the selection changes from the last one to another, just add the button to the manager. However, the fieldChanged method on the listener interface is called anytime the user scrolls through the choices (without clicking on the trackwheel to change the actual selection). I need to make the button visible only if the selection actually changes. I tried to override the navigationclick and navigationunclick on the choicefield to understand when the user actually clicks on the trackwheel (trackwheelclick and trackwheelunclick can also be used) but the problem with those methods is that they do not capture the final trackwheel click to change the selection. I mean, when you first click on the choicefield, navigationclick and then navigationunclick is invoked, and after you scroll through the choices and click on the trackwheel again to change the selection, no method is invoked. Because of this I can not figure out whether the user actually changed the selection and can not update the button accordingly. I hope I was able to explain everything Is there anyone to throw any ideas?

Thanks!
Offline  
Old 12-19-2007, 03:22 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

how about ChoiceField.getSelectedIndex()? You can check it whenever your changelistener fires.

hth,
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-20-2007, 09:41 AM   #3 (permalink)
New Member
 
Join Date: Aug 2007
Model: 7100T
PIN: N/A
Carrier: cingular
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

yeah i'm already using getSelectedIndex() to get the selection but the source of my problem is the timing of the changelistener fires. it fires BEFORE the user clicks on the trackwheel to actually change the selection. so if you have 3 items and scroll through them without changing the current selection, the changelistener is notified 3 times. if i was able to distinguish between a trackwheel click that opens the selections and a trackwheel click that actually changes the selection, i would be fine. but since this is not the case, i cant figure out a solution.
Offline  
Old 12-20-2007, 02:59 PM   #4 (permalink)
vph
Knows Where the Search Button Is
 
Join Date: Dec 2007
Model: 8700
PIN: N/A
Carrier: Cingular
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got into similar problem, and here is my solution

if( context == FieldChangeListener.PROGRAMMATIC ) { // this happens when users scroll
...
} else { // this happens when users select it

....
}


--vph
Offline  
Old 12-21-2007, 10:33 AM   #5 (permalink)
New Member
 
Join Date: Aug 2007
Model: 7100T
PIN: N/A
Carrier: cingular
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks, i've tried that. but for some reason, the context is always non-programmatic, both for a scroll or selection.
Offline  
Old 02-12-2009, 11:08 AM   #6 (permalink)
New Member
 
Join Date: Feb 2009
Model: .
PIN: N/A
Carrier: .
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check context == ChoiceField.CONTEXT_CHANGE_OPTION
Offline  
Old 02-16-2009, 09:29 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2008
Model: none
Carrier: sprint
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wirelessly posted

I believe that when scrolling the context equals "0", and when selecting it equals "2". It may be the opposite. I don't know what the values mean, but it worked by me.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.