小编Ruc*_*wat的帖子

如何获取在android中动态创建的单选按钮的id

在我的活动中,我正在创建一个动态的无线电组.我在Sqlite数据库中有一些问题和答案,在活动中检索它们然后在RadioGroup中设置.这工作正常.但在那之后,我希望用户获得所选的单选按钮的所有ID以将它们存储在数据库中.一般来说,当我们有选项的ID时,我们会这样做:

            id1=rdgroup1.getCheckedRadioButtonId();
            que1=(RadioButton)findViewById(id1);
            ans1=que1.getId()+""; // so here I will get radio button's ID.
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,我将如何获得所选单选按钮的ID.这是我动态创建radiogroup的代码.

     LinearLayout mLinearLayout = (LinearLayout) findViewById(R.id.linear1);
        c1=db.rawQuery("SELECT * FROM QueTable WHERE AgeGroup='10-20'", null);
        c1.moveToFirst();
        int i = c1.getCount();
        if(i > 0)
        {
            Log.w("START", "start");
            while (i > 0)
            {
                TextView title = new TextView(this);
                questions = c1.getString(1);
                title.setText(questions);
                title.setTextColor(Color.BLACK);
                mLinearLayout.addView(title);
                // create radio button

                answers=c1.getString(2);
                String[] answer = answers.split(",");
                rb = new RadioButton[5];
                rg = new RadioGroup(this);
                rg.setOrientation(RadioGroup.VERTICAL);

                int k = answer.length;

                for (int j = 0; …
Run Code Online (Sandbox Code Playgroud)

java sqlite android android-sqlite android-radiogroup

5
推荐指数
1
解决办法
3336
查看次数