将动态Radiobutton添加到RadioGroup

Cao*_*ong 0 android

public class MCQSample extends Activity implements OnClickListener{

    TextView title;
    String gotBread;
    RadioGroup AnswerRG;
    int value ;
    int value1;



    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mcqsample); 
        title = (TextView) findViewById(R.id.abc);
        nextP = (Button) findViewById(R.id.nextP);
        backP = (Button) findViewById(R.id.backP);
        AnswerRG = (RadioGroup) findViewById(R.id.AnswerRG);


            Bundle b = getIntent().getExtras();
            value = b.getInt("key", 0);

        }
    }
Run Code Online (Sandbox Code Playgroud)

嗨伙计们,我正在做Android应用程序并坚持创建动态单选按钮.因为我不知道我需要多少按钮(这取决于值 - 用户输入).我读了一些可以在Layout上添加的帖子,但我想添加到radioGroup中.有什么办法吗?谢谢

Com*_*are 5

步骤#1:RadioButton通过其构造函数创建一个新的,并根据需要进行配置.

第2步:打电话addView()给你RadioGroup添加RadioButton它.

第3步:没有第3步