【发布时间】:2015-07-15 18:57:33
【问题描述】:
我在如何在变量中传递 arrayList 的所有值时遇到问题。有没有办法可以将不同单选按钮的所有值获取到单个变量中。这是我的带有评论的程序
ArrayList < String > list1 = new ArrayList < String > ();
String rg1 = "*";
String rg2 = "*";
String rg4 = "*";
String rg5 = "*";
list1 = "*"; // Getting error here it only accepts string , how declare list1 with ArrayList
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();
int spec2 = rgSpecialty2.getCheckedRadioButtonId();
RadioButton rBtSpec = (RadioButton) dia.findViewById(spec);
RadioButton rBtSpec2 = (RadioButton) dia.findViewById(spec2);
list1.add((String) rBtSpec.getText());
list1.add((String) rBtSpec2.getText());
}
TuitionFee = Integer.parseInt(theFilter[5]);
theFilter[0] = rg1;
theFilter[1] = rg2;
theFilter[3] = rg4;
theFilter[4] = rg5;
theFilter[6] = list1; // getting error within this part, how can I assign arrayList values here ?
fragment = new SchoolListFragmentFilter();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.content_frame, fragment)
.addToBackStack(null).commit();
mDrawerLayout.closeDrawer(expListView);
dia.dismiss();
这里是我从单选按钮中过滤这些值的地方
if (sReg[loop].equalsIgnoreCase(thisFilter[0])
&& sAdmin[loop].equalsIgnoreCase(thisFilter[1])
&& sAmbience[loop].equalsIgnoreCase(thisFilter[3])
&& amountTF >= theTuitionFee
&& sSpecialty[loop][subloop].equalsIgnoreCase(thisFilter[4])
&& sSpecialty[loop][subloop].equalsIgnoreCase(thisFilter[6])
这是用于过滤 sReg 并从其余部分中全选的附加程序。
(sReg[loop].equalsIgnoreCase((String)thisFilter[0])
&& ((String)thisFilter[1]).equalsIgnoreCase("*")
&& ((String)thisFilter[3]).equalsIgnoreCase("*")
&& amountTF == 0
&& ((String)thisFilter[4]).equalsIgnoreCase("*")
&& ((String)thisFilter[6]).equalsIgnoreCase("*")) {
list.add(sList[loop]);
【问题讨论】:
-
您可能想要使用
add()方法。list1.add("*"); -
过滤器[5]是字符串吗。
-
公共静态字符串 theFilter[] = new String[6];在这里,先生
-
应该像 theFilter[5]=(String)list1.get(0);//根据索引'0'从列表对象中获取值。