Helo i am trying to populate a listView with data stored in a sqLite.
After i select a product i want all the reference of that product to
go on the same line like i drew in the picture.
Can i make the ArrayAdapter put all records in the same xml?
My code looks like this: The cursor that returns all records:
public Cursor getAllRows() {
String where = null;
// query the DBAdapter
Cursor cursor = db.query(true, TABLE_NAME, ALL_KEYS, where, null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
Adding data to arrayList:
public ArrayList<String> fromCursorToArrayListString(Cursor c){
ArrayList<String> result = new ArrayList<String>();
c.moveToFirst();
for(int i = 0; i < c.getCount(); i++){
String row_PRODUCT = c.getString(c.getColumnIndex(KEY_PRODUCT));
String row_PRICE = c.getString(c.getColumnIndex(KEY_PRICE));
String row_TYPE = c.getString(c.getColumnIndex(KEY_TYPE));
result.add(row_PRODUCT);
result.add(row_PRICE);
result.add(row_TYPE);
c.moveToNext();
}
return result;
}
In the mainActivity i wrote this:
ListView listView = (ListView) findViewById(R.id.new_list_listView);
Cursor cursor = newListDBAdapter.getAllRows();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.custom_product_layout_new_list,R.id.custom_product_layout_new_list_productName,newListDBAdapter.fromCursorToArrayListString(cursor));
listView.setAdapter(arrayAdapter);