private void createRadioButton() { final RadioButton[] rb = new RadioButton[5]; RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL for(int i=0; i<5; i++){ rb[i] = new RadioButton(this); rg.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout rb[i].setText("Test"); } ll.addView(rg);//you add the whole RadioGroup to the layout ll.addView(submit); submit.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { for(int i = 0; i < 5; i++) { rg.removeView(rb[i]);//now the RadioButtons are in the RadioGroup } ll.removeView(submit); Questions(); } }); }
RadioGroup ll = new RadioGroup(this); ll.setOrientation(LinearLayout.HORIZONTAL);
private void createRadioButton() { final RadioButton[] rb = new RadioButton[5]; RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL for(int i=0; i<5; i++){ rb[i] = new RadioButton(this); rg.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout rb[i].setText("Test"); } ll.addView(rg);//you add the whole RadioGroup to the layout ll.addView(submit); submit.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { for(int i = 0; i < 5; i++) { rg.removeView(rb[i]);//now the RadioButtons are in the RadioGroup } ll.removeView(submit); Questions(); } }); }
radioGroup = new RadioGroup[4]; for (int i = 0; i < 4; i++) { radioGroup[i] = new RadioGroup(this); linearLayout.addView(radioGroup[i]); } finishButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < 4; i++) { radioGroup[i].clearCheck(); } } });
//I added these for posterity, I'm sure however you get these references is fine LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); RadioGroup radio_group = new RadioGroup(this); //Get the button, rename it, then add it to the group. for(int i = 0; i < options.length(); i++) { JSONObject option = options.getJSONObject(i); RadioButton option_view = (RadioButton)vi.inflate(R.layout.poll_option, null); option_view.setText(option.getString("response")); radio_group.addView(button); }
RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL for (int i = 0; i< typeArrayList.size(); i++) { radioButtons[i] = new RadioButton(MainActivity.this); radioButtons[i].setId(i); radioButtons[i].setText(typeArrayList.get(i).toString()); if(i==0) { radioButtons[i].setChecked(true); } rg.addView(radioButtons[i]); // add dynamic radio buttons to radio group } typeLayout.addView(rg); // add radio group to view
rbHide = (RadioButton)findViewById(R.id.rbHide); rbShow = (RadioButton)findViewById(R.id.rbShow); RadioGroup rg = new RadioGroup(this); rg.addView(rbHide); rg.addView(rbShow); rbHide.setOnCheckedChangeListener(this); rbShow.setOnCheckedChangeListener(this);
TableRow.LayoutParams rg_params = new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3f); RadioGroup radio_group=new RadioGroup(this); radio_group.setOrientation(RadioGroup.HORIZONTAL); radio_group.setLayoutParams(rg_params); RadioButton dry=new RadioButton(this); RadioGroup.LayoutParams params_soiled = new RadioGroup.LayoutParams(getBaseContext(), null); params_soiled.setMargins(10, 0, 10, 0); dry.setLayoutParams(button_params);
final RadioButton[] rb = new RadioButton[20]; RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.VERTICAL); for(int i=0; i<20; i++){ rb[i] = new RadioButton(this); rg.addView(rb[i]); rb[i].setText(" " + ContactsActivity.phonetype.get(i) + " " + ContactsActivity.phone.get(i)); rb[i].setId(i + 100); } ll.addView(rg);//you add the whole RadioGroup to the layout
RadioGroup radioGroup = new RadioGroup(this); List<LocationTypeEnum> warningTypes = preferences.getWarningTypes(); for (LocationTypeEnum enumElement : warningTypes) { RadioButton radio = new RadioButton(this); radio.setText(enumElement.toString()); //First, add the radio to the group radioGroup.addView(radio, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); //Only after that you can check it. radio.setChecked(enumElement.intValue == userDefinedLocation.getType().intValue); }
private void createRadioButton() { final RadioButton[] rb = new RadioButton[5]; RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL for(int i=0; i<5; i++){ rb[i] = new RadioButton(this); rb[i].setText(" " + ContactsActivity.phonetype.get(i) + " " + ContactsActivity.phone.get(i)); rb[i].setId(i + 100); rg.addView(rb[i]); } ll.addView(rg);//you add the whole RadioGroup to the layout }
final RadioButton[] rb = new RadioButton[4]; RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL for(int i=0; i<4; i++){ rb[i] = new RadioButton(this); rg.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout rb[i].setText("Test"); } ll.addView(rg);//you add the whole RadioGroup to the layout ll.addView(submit);
final RadioGroup rg = new RadioGroup(this); // create the RadioGroup rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL for (int i = 0; i < items.size(); i++) { RadioButton rb = new RadioButton(this); rb.setText(items.get(i)+""); rg.addView(rb); }
... RadioGroup rg = new RadioGroup(this); rg.setOrientation(RadioGroup.HORIZONTAL); rg.addView(rb1); rg.addView(rb2); rg.addView(rb3); row.addView(rg); ...
//Create Radio Button Answers RadioGroup radioGroup = new RadioGroup(this); radioGroup.setOrientation(RadioGroup.VERTICAL); for (Answer an : answers) { if (an.Question == qn) { String answers_log = " " + an.getAnswer(); RadioButton radioButton = new RadioButton(this); radioButton.setText(answers_log); radioGroup.addView(radioButton); } }
RadioGroup radioGroup = new RadioGroup(this); //Cycle begin RadioButton rButton = (RadioButton)findViewById(R.id.my_radiobutton); // OR RadioButton radioButton = new RadioButton(this); radioButton .setText(R.string.radio_group_snack); radioButton .setId(R.id.snack); radioGroup.addView(rButton); radioGroup.addView(radioButton); //Cycle end
RadioGroup rgSituacao = new RadioGroup(this); ... RadioButton rbOk = new RadioButton(this); rbOk.setLayoutParams(ParamWCWC); rbOk.setText("OK"); rgSituacao.addView(rbOk); rbOk.setChecked(situacao.equals("ok"));
for (Question qn : questions) { RadioGroup answerGroup = new RadioGroup(this); answerGroup.setOrientation(RadioGroup.VERTICAL); for (Answer an : qn.getAnswers()) { if (qn.getID() == an.getQuestion_id_answer()) { RadioButton answer = new RadioButton(this); answer.setText(an.getAnswer()); answerGroup.addView(answer); } } linearLayout.addView(answerGroup); }
RadioButton rBtn1 = new RadioButton(this); RadioButton rBtn2 = new RadioButton(this); rBtn1.setText("radio button 1"); rBtn2.setText("radio button 2"); //Add all your RadioButtons the same way. RadioGroup group = new RadioGroup(this); group.addView(rBtn1); group.addView(rBtn2); menu.add(0, group.getId(), 0, "whatever");
RadioGroup group = new RadioGroup(this); group.setOrientation(RadioGroup.HORIZONTAL); RadioButton btn1 = new RadioButton(this); btn1.setText("BTN1"); group.addView(btn1); RadioButton btn2 = new RadioButton(this); group.addView(btn2); btn2.setText("BTN2"); .... RadioButton btnN = new RadioButton(this); group.addView(btnN); btnN.setText("BTNN"); yourLayout.addView(group);