0

I'm stuck on a query ... I go to the point. Basically I have a table with 2 columns BREAD, DETAILS. I want to see everything in a ListView and not in a ExpandableListview, so I should change the query that I have created, I have done so, but I do not get the desired result, this:

EXAMPLE RECORDS IN THE TABLE:

BREAD - DETAILS

bread1 - flour

bread1 - yeast

bread1 - oil

bread1 - burnt

I want to see a result in ListView like this:

bread1

flour

yeast

oil

burnt

This the query:

String sql = "SELECT _id,BREAD, DETAILS FROM TABLE GROUP BY BREAD";
    Cursor c = db.rawQuery(sql, null);

    while (c.moveToNext()){
        Dettaglio d = new Dettaglio();

        d.id = c.getString(0);
        d.bread = c.getString(1);
        d.details = c.getString(2);         


        dettagli.add(d);
    }
    c.close();


db.close();
user3608814
  • 561
  • 1
  • 8
  • 23
  • Have a look at the ExpandableListView: http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/ – Phantômaxx Oct 13 '14 at 16:19
  • I think you mean this: SELECT _id, BREAD, DETAILS FROM TABLE WHERE BREAD = 'bread1'. This will show the details from one particular bread. – Rob Meeuwisse Oct 13 '14 at 16:19

1 Answers1

0

Group by basically returns only one row for a particular group. you need to use order by

SELECT _id,BREAD, DETAILS FROM TABLE ORDER BY BREAD

Now read the first row and store the Bread value in a variable and loop through the rows for Details. When the bread value changes consider it as a new Bread starting and handle it appropriately.

Panther
  • 8,938
  • 3
  • 23
  • 34
  • can u have a look to this problem http://stackoverflow.com/questions/38435531/android-setting-sqlite-database-values-in-an-listview – Addi.Star Jul 18 '16 at 12:11