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(); } }); }
rdbtn.setId((row * 2) + i); rdbtn.setText("Radio " + rdbtn.getId()); ll.addView(rdbtn);
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(); } }); }
//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
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 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);
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
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 }
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); }
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);
LinearLayout layout_name = (LinearLayout) findViewById(R.id.layout_name); 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].setId(i);//Setting id for the RadioButton rb[i].setText("Test"); } rg.check(3);//Checking pirticular RadioButton with id // 3 is that RadioButton Id name layout_name.addView(rg);//you add the whole RadioGroup to the layout
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");
RelativeLayout rlaAccessPoints; RadioGroup rg; private void PopulateAccessPoints(List<clsAccessPoint> accessPoints){ rg = new RadioGroup(this); for (clsAccessPoint acp : accessPoints) { RadioButton rd = new RadioButton(this); rd.setText(acp.ID + ": " + acp.Name); rg.addView(rd); if (Settings.AccessPointID.equals(acp.ID)){ rd.setChecked(true); } } rlaAccessPoints.addView(rg); }
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); }
//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 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); }