I have seen that this can be done for ListView where you can just grab the string-array values from strings.xml and populate the ListView dynamically depending on the number of listed items.
But I was wondering if the same feat can be done using Radio Buttons and Radio Button Group?
I've come across this piece of code
RadioGroup rgp= (RadioGroup) findViewById(R.id.radiogroup);
RadioGroup.LayoutParams rprms;
for(int i=0;i<3;i++){
RadioButton radioButton = new RadioButton(this);
radioButton.setText("new"+i);
radioButton.setId("rbtn"+i);
rprms= new RadioGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rgp.addView(radioButton, rprms);
}
And was wondering how I can modify the radioButton.setId("rbtn"+i) to grab string-array values from the strings.xml file instead.
Use String[] foo_array = getResources().getStringArray(R.array.foo_array); to read array from strings.xml. Then loop through the obtained array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With