Display header only when chlid is NOT NULL using Expandablelistview android studio -sqlite

前端 未结 1 1606
悲&欢浪女
悲&欢浪女 2021-01-26 08:54

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 d

相关标签:
1条回答
  • 2021-01-26 09:27

    I believe that you want a query based upon :-

    SELECT * FROM OrganAnatomy WHERE Pharynx IS NOT NULL ORDER BY Organ_features;
    

    This would result in :-

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

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

    could be :-

        public Cursor getDatabase() {
            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.
    0 讨论(0)
提交回复
热议问题