指派了所有检查项目到一个变量 [英] Assigning all check items into a variable

查看:102
本文介绍了指派了所有检查项目到一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在分配给一个变​​量,从检查的项目中的所有值?如果单选按钮有此code .getCheckedRadioButtonId(),一下一下的复选框。这里是我的复选框XML布局。

Is it possible to assign all the values from checked items in a single variable ? If radio button have this code .getCheckedRadioButtonId(), what about the checkboxes. Here's my xml layout for checkboxes.

<CheckBox
                android:id="@+id/cbFacilities"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Facility1"
                android:textColor="#000000"
                android:textSize="20dp"
                android:textStyle="bold" />
            <CheckBox
                android:id="@+id/cbFacilities2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Facility2"
                android:textColor="#000000"
                android:textSize="20dp"
                android:textStyle="bold" />
            <CheckBox
                android:id="@+id/cbFacilities3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Facility3"
                android:textColor="#000000"
                android:textSize="20dp"
                android:textStyle="bold" />

如果我检查所有项目,并将其分配给变量 X 含义。 X =基金1 Facility2 Facility3

Meaning if I check all items and assign it to variable x. x = Facility1 , Facility2 and Facility3 ?

String rg1 = "*";
                                String rg2 = "*";
                                String rg4 = "*";
                                String rg5 = "*";
                                theFilter[5] = "0";
                                if (cbRegAffil.isChecked()) {
                                    int reg = rgRegAffil
                                            .getCheckedRadioButtonId();
                                    RadioButton rBtReg = (RadioButton) dia
                                            .findViewById(reg);
                                    rg1 = (String) rBtReg.getText();

                                }
                                if (cbAdmin.isChecked()) {
                                    int adm = rgAdmin
                                            .getCheckedRadioButtonId();
                                    RadioButton rBtAdm = (RadioButton) dia
                                            .findViewById(adm);
                                    rg2 = (String) rBtAdm.getText();
                                }

                                if (cbAmbience.isChecked()) {
                                    int amb = rgAmbience
                                            .getCheckedRadioButtonId();
                                    RadioButton rBtAmbience = (RadioButton) dia
                                            .findViewById(amb);
                                    rg4 = (String) rBtAmbience.getText();
                                }
                                if (cbTuition.isChecked()) {
                                    theFilter[5] = spin.getSelectedItem()
                                            .toString();
                                }
                                if (cbSpecialty.isChecked()) {
                                    int spec = rgSpecialty
                                            .getCheckedRadioButtonId();
                                    RadioButton rBtSpec= (RadioButton) dia
                                            .findViewById(spec);
                                //  rg5 = (String) rBtSpec.getText();

                                }
                                if (cbFacilities.isChecked()||cbFacilities2.isChecked()||cbFacilities3.isChecked()) {
                //**I want to assign the values checked here with the variable rg5**
                                } 

当你注意到林分配单选值到一个变量,这个时候在节目的最后部分,cbFacilities1-3的,如果他们检查了价值将分配给持有字符串值一个变量。

As you notice Im assigning radiobutton value into a variable, this time in the last part of the program, the value of cbFacilities1-3 if they're checked will assign to a single variable that holds string values.

推荐答案

好吧,我想你可以做它持有的答案布尔值的数组。

Well, i think you could do an array of booleans which hold the answers.

可能看起来像这样:

boolean[] checkboxAnswers = new boolean[3];
checkboxAnswers[0] = checkbox1.getChecked();
checkboxAnswers[1] = checkbox2.getChecked();
checkboxAnswers[2] = checkbox3.getChecked();

这篇关于指派了所有检查项目到一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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