我遇到了如何在变量中传递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]);
答案 0 :(得分:1)
将list1 = "*";
替换为list1.add("*");
或者您可以在构造函数中执行此操作:
List<String> list1 = new ArrayList<>(Arrays.asList("val1", "val2", "val3"));
现在可以通过以下编辑来使用theFilter[6] = list1;
。
编辑:
用Object theFilter[]=new Object[6]
和
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])
由:
if (sReg[loop].equalsIgnoreCase((String)thisFilter[0])
&& sAdmin[loop].equalsIgnoreCase((String)thisFilter[1])
&& sAmbience[loop].equalsIgnoreCase((String)thisFilter[3])
&& amountTF >= theTuitionFee
&& sSpecialty[loop][subloop].equalsIgnoreCase((String)thisFilter[4])
&& filtered(sSpecialty[loop][subloop], (List<String>)thisFilter[6]))
和您的过滤方法:
private boolean filteredOne(String val, List<String> values) {
boolean b = false;
for(String s:values) {
b |= s.equalsIgnoreCase(val);
}
return b;// true if one is equal
}
private boolean filteredAll(String val, List<String> values) {
boolean b = true;
for(String s:values) {
b &= s.equalsIgnoreCase(val);
}
return b;// true if all are equal
}