开发者

Creating dynamic controls

开发者 https://www.devze.com 2022-12-17 03:08 出处:网络
I am t开发者_Python百科rying to create a screen with some dynamic controls, well radio buttons to be precise purely for learning purposes.

I am t开发者_Python百科rying 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:


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号