我在我的Android应用程序中有listview with checkbox。我想保存arraylist<string>
中已选中复选框的ID。我想用它在我的查询中进行比较,但我在getcount()
中有错误,因为查询没有运行。
这里是我的代码&#34; Main.java&#34;:
public void clicksubmit() {
ArrayList<String> lst = new ArrayList<String>();
lst.clear();
String arrId = "";
System.out.println("check"+getListView().getCheckedItemIds().length);;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).isCek()) {
arrId = arrId + list.get(i).getIdGejala() +",";
}
}
arrId = arrId.substring(0, arrId.length() - 1);
Intent intent = new Intent(this, HasilDiagnosis.class);
intent.putExtra("arrId", arrId);
startActivity(intent);
Toast.makeText(this, "checked : " + arrId, Toast.LENGTH_LONG).show();
}
这是我的DBHandler.java:
public String[][] LihatHasil(String arrId){
try {
String arrData[][] = null;
SQLiteDatabase db = this.getWritableDatabase();
String strSQL = "SELECT p.*, COUNT( idRule ) as kejadian, "
+ "(SELECT COUNT( idRule ) kejadian FROM tbrule WHERE idGangguan=p.idGangguan) as peluang "
+ "FROM tbrule r JOIN tbgangguan p ON p.idGangguan = r.idGangguan "
+ "WHERE r.idGejala IN ("+arrId+")"
+ "ORDER BY kejadian DESC LIMIT 3 "
+ "GROUP BY r.idPenyakit";
Cursor cursor = db.rawQuery( strSQL, null);
if (cursor.moveToFirst()) {
arrData = new String[cursor.getCount()][cursor.getColumnCount()];
int i= 0;
do {
arrData[i][0] = cursor.getString(0);
arrData[i][1] = cursor.getString(1);
arrData[i][2] = cursor.getString(2);
arrData[i][3] = cursor.getString(3);
arrData[i][4] = cursor.getString(4);
i++;
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return arrData;
} catch (Exception e) {
return null;
}
有人可以帮助我。抱歉我的英文不好