My table name is DATABASE_TABLE2. I have 5 columns in that table. Now the statement I want to make is SELECT * DATABASE_TABLE2 Where REV_FACILITY = "Toilets"
And I want to display in an array list view.. This is the code I have tried and it is crashing. I know the problem is on the database method but i dont know what to do
private void displayListView() {
Cursor cursor = dbHelper.getAllToilets();
startManagingCursor(cursor);
// The desired columns to be bound
String[] columns = new String[]{
SQL.KEY_REV_STATION_NAME,
SQL.KEY_DATE,
SQL.KEY_REV_FACILITY,
SQL.KEY_RATING,
SQL.KEY_COMMENT
};
// the XML defined views which the data will be bound to
int[] to = new int[]{
R.id.SRevName,
R.id.SRevDate,
R.id.SRevFacility,
R.id.SRateBar,
R.id.SRevComment,
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
final SimpleCursorAdapter myCursorAdapter =
new SimpleCursorAdapter(
this, R.layout.review_list,
cursor,
columns,
to);
myCursorAdapter.setDropDownViewResource(android.R.layout.simple_selectable_list_item);
ListView listView = (ListView) findViewById(R.id.ToiletReviews);
// Assign adapter to ListView
listView.setAdapter(myCursorAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
public Cursor getAllToilets() {
//String where = null;
String where = KEY_REV_FACILITY = "Toilets";
Cursor c = db.query(true, DATABASE_TABLE2, ALL_REV_KEYS,
where, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}