I am having a problem with the way my ExpandableListView selects a child item from my SQLite database. The code below fills my ExpandableListView with KEY_PHRASE for the parent and KEY_ROMANIZATION for child. The group items display fine, but when the parent is clicked, every single row from KEY_ROMANIZATION is displayed, rather than only one.
Below is part of my activity:
private void fillData() {
phrases = mydb.getPhrase();
ExpandableShell.this.startManagingCursor(phrases);
phrases.moveToFirst();
ExpandableListView elv = (ExpandableListView) ExpandableShell.this.findViewById(R.id.shell_expList);
MyExpandableListAdapter mAdapter = new MyExpandableListAdapter(phrases, this,
R.layout.group_item, // Your row layout for a group
R.layout.child_item, // Your row layout for a child
new String[]{"KEY_PHRASE"}, // Field(s) to use from group cursor
new int[]{R.id.laptop}, // Widget ids to put group data into
new String[]{"KEY_ROMANIZATION"}, // Field(s) to use from child cursors
new int[]{R.id.laptop}); // Widget ids to put child data into
elv.setAdapter(mAdapter); // set the list adapter.
}
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {
public MyExpandableListAdapter(Cursor cursor, Context context,int groupLayout,
int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
int[] childrenTo) {
super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childrenFrom, childrenTo);
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
Cursor childCursor = mydb.getPhraseChild(groupCursor.getString(groupCursor.getColumnIndex("KEY_ROWID")));
ExpandableShell.this.startManagingCursor(childCursor);
childCursor.moveToFirst();
return childCursor;
}
and here are the group and child cursors from my Database class:
public Cursor getPhrase() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"1 _id", "KEY_ROWID", "KEY_PHRASE"};
String sqlTables = "mainTable";
qb.setTables(sqlTables);
Cursor cursor = qb.query(db, sqlSelect, null,null,null,null,null,null,null);
cursor.moveToFirst();
return cursor;
}
public Cursor getPhraseChild(String mainTable) {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"1 _id", "KEY_ROWID", "KEY_ROMANIZATION"};
String sqlTables = "mainTable";
qb.setTables(sqlTables);
Cursor cursor = qb.query(db, sqlSelect, null,null,null,null,null,null,null);
cursor.moveToFirst();
return cursor;
}
I know the problem has something to do with my Cursors and SQLite select but I'm having a lot of trouble trying to fix it. Any help/advice would be appreciated!
Aucun commentaire:
Enregistrer un commentaire