1
我想用SimpleCursorTreeAdapter構建expandableList,但是我的列表沒有創建組,它重複每個子元素作爲組元素。expandableList問題
我的數據都是形成KEY_ROWID,KEY_NAME,KEY_EMAIL,KEY_ILID,KEY_KURUMID,KEY_BOLGEID
我DATAS:
(db,"Asli", "[email protected]", 1, 1, 1);
(db,"Osman Can", "[email protected]", 1, 1, 1);
(db,"Abuzer Kadayif", "[email protected]", 1, 2, 1);
(db,"Emre", "[email protected]", 1, 3, 2);
(db,"Deniz", "[email protected]", 1, 4, 2);
(db,"Simon Garfunkel", "[email protected]", 1, 5, 0);
(db,"Eric Clapton", "[email protected]", 1, 6, 0);
(db,"Neil Young", "[email protected]", 1, 5, 0);
,這是我的代碼:
String sqlString = "SELECT * " + " FROM " + Items.DATABASE_TABLE;
Cursor mCursor = db.rawQuery(sqlString, null);
SimpleCursorTreeAdapter mAdapter = new SimpleCursorTreeAdapter(this,
mCursor, R.layout.row, R.layout.exprow,
//createGroupList(),
new String[] { Items.KEY_BOLGEID },
new int[] { R.id.txtItem },
R.layout.exprow, R.layout.exprow,
new String[] { Items.KEY_EMAIL,Items.KEY_NAME }, new int[] { R.id.dscItem, R.id.manuItem }) {
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
String tempGroup = groupCursor.getString(groupCursor
.getColumnIndex(Items.KEY_BOLGEID));
DbHelper dbh = new DbHelper(BrowseActivity.this);
SQLiteDatabase db = dbh.getWritableDatabase();
String sqlString = "SELECT " + Items.KEY_ROWID + ", "
+ Items.KEY_EMAIL + ", " + Items.KEY_NAME + ", "
+ Items.KEY_KURUMID + ", " + Items.KEY_BOLGEID + ", "
+ Items.KEY_ILID + " FROM " + Items.DATABASE_TABLE
+ " WHERE " + Items.KEY_BOLGEID + "= " + tempGroup
;
Cursor mCursor = db.rawQuery(sqlString, null);
return mCursor;
}
};
browseView.setAdapter(mAdapter);
}
我的結果應該是:
Group 1:
(db,"Asli", "[email protected]", 1, 1, 1);
(db,"Osman Can", "[email protected]", 1, 1, 1);
(db,"Abuzer Kadayif", "[email protected]", 1, 2, 1);
Group 2:
(db,"Emre", "[email protected]", 1, 3, 2);
(db,"Deniz", "[email protected]", 1, 4, 2);
Group 3:
(db,"Simon Garfunkel", "[email protected]", 1, 5, 0);
(db,"Eric Clapton", "[email protected]", 1, 6, 0);
(db,"Neil Young", "[email protected]", 1, 5, 0);
但它是 3次組1 2次組2 3次組0
我試圖改變groupCursor的SQL,但它崩潰。
你還需要方向嗎? – Barak
我正在做類似這裏的東西http://stackoverflow.com/questions/10611927/simplecursortreeadapter-and-cursorloader – toobsco42