BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 05-27-2009, 08:46 AM   #1 (permalink)
itp
Knows Where the Search Button Is
 
Join Date: Jul 2008
Model: none
PIN: N/A
Carrier: none
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default getSelectedIndex() on radiobuttongroup

Please Login to Remove!

I want to build a form with radio buttons and a submit button. I use a FieldChangeListener to capture selection. I think getSelectedIndex() is supposed to retrieve button selected, but I keep getting a null when the button is clicked. I was able to overcome this with an inner class on radiobuttongroup , but I know it is not the best solution.
Can anyone advise?

PHP Code:
 
public class fieldTest extends MainScreen implements FieldChangeListener
{
    
ButtonField button1 null;
    
RadioButtonField radioButtonF1 null;
    
RadioButtonField radioButtonF2 null;
    
RadioButtonField radioButtonF3 null;

    
int valueOfRadioButton 0;
    public 
fieldTest()
    {  
        
super(DEFAULT_MENU DEFAULT_CLOSE);
        
LabelField title = new LabelField("RadioButtonField Example" ,LabelField.ELLIPSIS |  LabelField.USE_ALL_WIDTH); 
        
setTitle(title);  
        
        
LabelField lblAlblB;
        
lblA = new LabelField("Here comes some radioButtonFields in a RadioButtonGroup:");
        
this.add(lblA); 
        
        final 
RadioButtonGroup rbGroup = new RadioButtonGroup();
        
RadioButtonField radioButtonF1 = new RadioButtonField("Radio Option 1"rbGrouptrue);    // turn the first one "on"
        
RadioButtonField radioButtonF2 = new RadioButtonField("Radio Option 2"rbGroupfalse);
        
RadioButtonField radioButtonF3 = new RadioButtonField("Radio Option 3"rbGroupfalse);
        
this.add(radioButtonF1);
        
this.add(radioButtonF2);
        
this.add(radioButtonF3);
        
        
button1 = new ButtonField("Submit");            
        
this.add(button1);
        
button1.setChangeListener(this);        
        
rbGroup.setChangeListener(new FieldChangeListener() {
                      public 
void fieldChanged(Field fieldint context)
                     {          if(
rbGroup.getSelectedIndex() == 0)             
                                               
valueOfRadioButton 0;
                                if(
rbGroup.getSelectedIndex() == 1)             
                                               
valueOfRadioButton 1;          
                                if(
rbGroup.getSelectedIndex() == 2)             
                                               
valueOfRadioButton 2;          
                      }       
               });
              
        
radioButtonF1.setChangeListener(this);
        
radioButtonF2.setChangeListener(this);
        
radioButtonF3.setChangeListener(this);
        
    }
    
// over-ride default onSavePrompt method to avoid being asked if I want to save each time.
    
public boolean onSavePrompt()
    {
        return 
true;
    }         
    
    public 
void fieldChanged(Field fieldint context)
    {
         if(
field instanceof ButtonField)
        {    
             if(
valueOfRadioButton == 0)
                 
Dialog.alert("Option One was selected!");             
             if(
valueOfRadioButton == 1)
                 
Dialog.alert("Option Two was selected!");             
             if(
valueOfRadioButton == 2)
                 
Dialog.alert("Option Three was selected!");              
        }        
    }    

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

1PC New Siemens 6ES7 953-8LL20-0AA0 Micro Memory Card 6ES79538LL200AA0
$315.0
1PC New Siemens 6ES7 953-8LL20-0AA0 Micro Memory Card 6ES79538LL200AA0 pictureSpiretro 4 x 6 inch Memorial Pet Dog Cat Wood Picture Frame Plexiglass Tabletop
$25.6
Spiretro 4 x 6 inch Memorial Pet Dog Cat Wood Picture Frame Plexiglass Tabletop picture1Pc New Mitsubishi Memory Card A3NMCA-24 A3NMCA24 PLC One year warranty
$172.0
1Pc New Mitsubishi Memory Card A3NMCA-24 A3NMCA24 PLC One year warranty pictureKINGSTON MEMORY UNIT KTD-NPOP/32 CE 1360-032.A00 K2 9901360.032 A00 M-3 94V-0 98
$9999.0
KINGSTON MEMORY UNIT KTD-NPOP/32 CE 1360-032.A00 K2 9901360.032 A00 M-3 94V-0 98 picture1Pc New Mitsubishi Memory Module A3NMCA-16 A3NMCA16 One year warranty
$245.0
1Pc New Mitsubishi Memory Module A3NMCA-16 A3NMCA16 One year warranty picture






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