hi, the radio buttons work fine. except for the second. when i click on that one, it gets stuck and won't uncheck. please see small self contained code sample below. i am using 4.0.3.

thanks

package small.example;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
public class SmallActivity extends Activity {
        @Override public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                LinearLayout main=new LinearLayout(this);
                main.setOrientation(LinearLayout.VERTICAL);
                int question=1;
                button=new Button(this);
                button.setText("Make a choice");
                main.addView(button);
                button.setId(question);
                setContentView(main);
                int answers=4;
                radioButtons=new RadioButton[answers];
RadioGroup radioGroup=addRadioButtonsToGroup(question,radioButtons);
                LinearLayout linearLayout=new LinearLayout(this);
                linearLayout.addView(radioGroup);
                linearLayout.setId(question);
                // radioButtons[0].setChecked(true);
                main.addView(linearLayout);
        }
private RadioGroup addRadioButtonsToGroup(int question,RadioButton[] radioButtons) {
                RadioGroup radioGroup=new RadioGroup(this);
                for(int i=0;i<radioButtons.length;i++) {
                        radioButtons[i]=new RadioButton(this);
radioButtons[i].setText("Question "+question+" Choice "+(i+1));
                        radioButtons[i].setId(i);
                        radioGroup.addView(radioButtons[i]);
                }
                
radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);
                radioGroup.setId(question);
                return radioGroup;
        }
        RadioButton[] radioButtons;
        Button button;
RadioGroup.OnCheckedChangeListener radioGroupOnCheckedChangeListener=new RadioGroup.OnCheckedChangeListener(){
                public void onCheckedChanged(RadioGroup group,int checkedId) {
                        int id=checkedId;
                        button.setText(radioButtons[id].getText());
                }
        };
}

---
co-chair http://ocjug.org/

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to