是否获得所有选定的单选按钮和动态创建的复选框值? [英] Get all the selected radio button and check box value created dyamically?

查看:66
本文介绍了是否获得所有选定的单选按钮和动态创建的复选框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存所有选择的答案(复选框和单选按钮)及其对应的问题,该问题在sqlite db的动态Textview中设置, 但是问题是当我单击保存按钮"时,只有上一次选择 单选按钮值将保存到sqlite,而不是所有选定值,并且也无法获得所有选定复选框值.
请帮助我.

I want to save all the selected answer(checkbox and radiobutton) and its corresponding question which is set in dynamic Textview in sqlite db , but the problem is when i am clicking "save button" only last selected radio button value is saved to sqlite , not all selected value and not able to get all selected check box value also .
Please help me .

save= (Button) findViewById(R.id.save);
        save.setOnClickListener(this);
        ll = (LinearLayout) findViewById(R.id.linearLayout1);

        for (int j = 0; j < Questions.length; j++) {
               tv = new TextView(this);
               tv.setId(j);
            tv.setText(Questions[j].getQuestionNo() + "."
                    + Questions[j].getQuestion());
            ll.addView(tv);

            Answer[] answer = Questions[j].getAnswer();
            if (Questions[j].getMultipleChoice().equalsIgnoreCase("false")) {
                rg = new RadioGroup(this);
                rg.setOrientation(RadioGroup.VERTICAL);
                RadioButton[] rb = new RadioButton[answer.length];
                for (int i = 0; i < answer.length; i++)
                {
                     // add radio buttons
                    rb[i] = new RadioButton(this);
                    rb[i].setText(answer[i].getLabel());
                    int id = Integer.parseInt(j + "" + i);
                    rb[i].setId(id);
                    rg.addView(rb[i]);
                            }
                ll.addView(rg);

            else 
                        {
                            // add checkboxes
                   for (int i = 0; i < answer.length; i++) {
                    cb = new CheckBox(this);
                    cb.setText(answer[i].getLabel());
                    int id = Integer.parseInt(j + "" + i);
                    cb.setId(id);

                    ll.addView(cb);
                                                            } 
                        } 


}



 public void onClick(View v) {
            switch (v.getId()) {
            case R.id.save:

                if (rg.getCheckedRadioButtonId() != -1) {
                    int id = rg.getCheckedRadioButtonId();
                    View radioButton = rg.findViewById(id);
                    int radioId = rg.indexOfChild(radioButton);
                    RadioButton btn = (RadioButton) rg.getChildAt(radioId);
                    String answer = (String) btn.getText();
                    //only last selected radio button value is coming 
                             }

                         // not able to get all the selected checkbox value
                break;

            default:
                break;
            }
        }

推荐答案

我不知道android.但是问题出现在struts2中.我通过生成如下所示的动态复选框解决了该问题.

I don't know android.But the issue arise me in struts2.I solved that issue by generating dynamic checkbox like below.

<s:iterator value="samplelist">
<input type="checkbox"  value="true" style="margin-top:2px;" name="p_<s:property value='profileId'/>
</s:iterator>

因此我通过使用for循环找出了是否在Java代码中对其进行了检查

so i have found out if it is checked or not in java code by using the for loop

for(int i=0;i<samplelist.size();i++)
request.getParameter("P_something");

这篇关于是否获得所有选定的单选按钮和动态创建的复选框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆