开发者

Creating dynamic controls

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜