0

我做了一个包含单选按钮的布局。我想将选定单选按钮的值传递给数据库,那么我怎样才能得到这个值。?代码如下..请帮助我..

private View drawRadioTypeQuestion(Question question, ArrayList<QuestionOption> questionOptions) {
        LinearLayout layout = new LinearLayout(this);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setPadding(5, 5, 5, 5);

        TextView tv = new TextView(this);
        tv.setText(question.Question_Order + ". " + question.Question_Title);
        tv.setTextSize(16);
        // tv.setTypeface(PhoneStatus.getRobotoMediumTypeface(this));
        layout.addView(tv);

        RadioGroup rg = new RadioGroup(this);
        rg.setOrientation(RadioGroup.VERTICAL);
        for (QuestionOption opt : questionOptions) {
            RadioButton rb = new RadioButton(this);
            rb.setText(opt.Question_Answer_Value);
            rb.setTextSize(16);
            rg.addView(rb);
        }
        layout.addView(rg);

        PhoneStatus.overrideFonts(QuestionListActivity.this, layout);
        tv.setTypeface(PhoneStatus.getRobotoMediumTypeface(this));
        return layout;
    }
4

2 回答 2

0

试试这个代码

   rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub
            RadioButton rb = (RadioButton) findViewById(checkedId);
            String value = rb.getText().toString();
        }
    });
于 2013-08-17T11:11:00.790 回答
0

在单选按钮上实现单击侦听器。在 onclick 事件中,将所选单选按钮的值添加到数据库..

访问此处获取官方文档

http://developer.android.com/guide/topics/ui/controls/radiobutton.html

http://android-er.blogspot.in/2009/11/radiogroup-and-radiobutton.html

于 2013-08-17T11:07:06.353 回答