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(); } }); }
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 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
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout linear=(LinearLayout) findViewById(R.id.linearlayout); final RadioButton[] rb = new RadioButton[5]; RadioGroup rg = new RadioGroup(this); //create the RadioGroup rg.setOrientation(RadioGroup.VERTICAL);//or RadioGroup.VERTICAL for(int i=0; i<5; i++){ rb[i] = new RadioButton(this); rb[i].setButtonDrawable(R.drawable.single_radio_chice); rg.addView(rb[i]); } LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); p.setMargins(10, 10, 10, 10); linear.addView(rg,p); }
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
public void getqlist(int comp) { LinearLayout ll = (LinearLayout) findViewById(R.id.variable); ll.removeAllViews(); xfiche=(ficheflag)?(fiche+1):fichetempo; String titre="Formulaire "+xfiche+"- Question "+(comp+1)+"/"+taille; TextView titreView =(TextView) findViewById(R.id.titre); titreView.setText(titre); int ii= Integer.parseInt(quest[comp][3].toString()); RadioButton[] rb = new RadioButton[ii]; RadioGroup rg = new RadioGroup(this); rg.setOrientation(RadioGroup.VERTICAL); int isel=Integer.parseInt(resp[comp][2].toString())-1; int bid=254211; // You give any integer ID for(int i=0; i<ii; i++){ rb[i] = new RadioButton(this); rb[i].setText(quest[comp][i+5].toString()); if (i==isel) rb[i].setId(bid); // You capure the previously selected radio button rg.addView(rb[i]); } ll.addView(rg);//you add the whole RadioGroup to the layout RadioButton tb=(RadioButton) findViewById(bid); // find the button by the Id tb.toggle(); // toggle it after diplaying the group }
private void createRadioButton() { List<Integer> objects = new ArrayList<Integer>(); objects.add(0); objects.add(1); objects.add(2); objects.add(3); objects.add(4); Collections.shuffle(objects); 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(objects.get(i)+""); } 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); } }); }
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);
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
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); } }
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { //Create another radio group here //then add it to the view RadioGroup rg2 = new RadioGroup(this); //create the RadioGroup rg2.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL rg2.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels); final Drawable drawableTop = getResources().getDrawable(R.drawable.document_icon); for (int i = 0; i < itemTypeArrayList.size(); i++) { if (itemTypeArrayList.get(i).getActive() == 1) { rb = new RadioButton(this); rg2.addView(rb); //the RadioButtons are added to the radioGroup instead of the layout rb.setText(itemTypeArrayList.get(i).getCode()); rb.setId(itemTypeArrayList.get(i).getId()); } } itemDetailsLinearLayout.addView(rg); } });
rg.setOrientation(RadioGroup.VERTICAL);
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); }
private void createRadioButton() { final RadioButton[] radioButton = new RadioButton[7]; RadioGroup radioGroup = new RadioGroup(this); radioGroup.setOrientation(RadioGroup.VERTICAL); for(int i = 0; i < 7; ++i) { radioButton[i] = new RadioButton(this); Button buttonView = new Button(this); buttonView.setText("Button " + i); radioGroup.addView(radioButton[i]); radioGroup.addView(buttonView); radioButton[i].setText("Test" + i); } line.addView(radioGroup); }
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);