tags:

views:

54

answers:

2

I am trying to create a screen with some dynamic controls, well radio buttons to be precise purely for learning purposes.

I have managed to add the radio button by referencing the radio group in the main.xml file.

RadioGroup rg = (RadioGroup)findViewById(R.Id.types);

RadioButton rb = new RadioButton(this);

rb.setText("some text!");

rg.addView(rb);

What I cannot figure out is how do I set the id of the radio button?

If use rb.setId() it wants an integer? I am trying to basicaly do the xml bit dynamically:

thanks

+1  A: 

rb.setId(int) is how you would set the ID. You say "it wants an integer?" as if you find that strange. All View IDs are integers so what else would you expect?

mbaird
A: 

well if you set it in the xml file as

The yadda appears in the R.java file as an autogenerated number. Therefore I was not sure that it was correct to assign any old number seeing as you pass text in the xml.

That text in the XML just refers to the int value in R.java
mbaird