I have two tables in my database – rooms and devices. Each room can have many devices. I want to make an expandable listview with room name as group and devices name and state as children (on or off).
Can any one give me a simple idea because I am kind of new with Android and all tutorials are hard to make
This is my database:
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists rooms (
id_room integer primary key autoincrement, "
+ "name_room text not null"
+ ");");
db.execSQL("create table if not exists devices (
id_device integer primary key autoincrement, "
+ "name_device text not null,"
+ "state_device text not null,"
+ "id_room references rooms"
+ ");");
}
Following is a very simple, no frills expandable list implementation.
You need two methods in your db helper class to gather the cursors you will need.
Then you need to set up your adapter (in your activity):
And finally call the adapter and set it to your list (in your activity):
Hope this helps!
EDIT
It should all come together like so:
EDIT 2
To catch clicks, set listeners in you activity: