Skip to content Skip to sidebar Skip to footer

Display Header Only When Chlid Is Not Null Using Expandablelistview Android Studio -sqlite

I'm trying to make an expendable list view with the header text being extratced from column 'Organ features' and child text is extratced from the pharynx column, this is my databas

Solution 1:

I believe that you want a query based upon :-

SELECT * FROM OrganAnatomy WHERE Pharynx ISNOT NULL ORDERBY Organ_features;

This would result in :-

enter image description here

To convert this for use by the SQLiteDatabasequery method, the code instead of being :-

public Cursor getDatabase() {
        return mDB.query(DATABASE_TABLE, null, null, null, null, null, DATABASE_GROUP_1);
    }

could be :-

publicCursorgetDatabase() {
        String whereclause = DATABASE_CHILD_1 + " IS NOT NULL";
        return mDB.query(DATABASE_TABLE, null, whereclause, null, null, null, DATABASE_GROUP_1);
    }
  • Note the above code is in-principle code and has not been tested, so may contain some errors.
  • Note no attempt has been made to apply this to the ExpanableListView, it has been assumed that the adapter handles the Cursor appropriately.
  • There is no IF statement as such (IF ??? EXISTS/ NOT EXISTS is where you you see IF used), rather a WHERE clause, which determines what rows are to be included (so in this case only include rows WHERE the Pharynx column IS NOT NULL).
    • The real equivalent to IF is the CASE WHEN .... ELSE .... END AS construct, although this isn't needed and also isn't suitable for this scenario.
    • There is also the HAVING clause but this expects a GROUP BY clause and acts upon the result rather than the input rows and is really used for post processing, e.g. you could have SELECT * FROM OrganAnatomy GROUP BY _id HAVING Pharynx IS NOT NULL ORDER BY Organ_features; (works as _id will be unique so every row will be in it's own group).
    • Using the HAVING clause is overkill/over-complicated in this scenario.

Post a Comment for "Display Header Only When Chlid Is Not Null Using Expandablelistview Android Studio -sqlite"