Использую SimpleCursorTreeAdapter для того что бы отобразить дерево:
- категории
- подкатегории
- товары
- подкатегории
На картинке показаны только группы и под группы.
Метод
protected Cursor getChildrenCursor(Cursor groupCursor) {}
выполняется при нажатии на категорию, меня интересует можно ли как то обработать нажатие на 'под категорию' так что бы потом каким то образом отобразить еще список товаров можно в этом же дереве либо уже в другом активити, или каким то другом способом?
public class AllProductsActivity extends Activity {
ExpandableListView elvMain;
DatabaseHandler db;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_market);
db = new DatabaseHandler(this);
Cursor categoryData = db.getCategoryData();
startManagingCursor(categoryData);
String[] groupFrom = { DatabaseHandler.COLUMN_NAME };
int[] groupTo = { android.R.id.text1 };
String[] childFrom = { DatabaseHandler.COLUMN_NAME };
int[] childTo = { android.R.id.text1 };
// create adapter and a custom list
SimpleCursorTreeAdapter sctAdapter = new MyAdapter(this, categoryData,
android.R.layout.simple_expandable_list_item_1, groupFrom,
groupTo, android.R.layout.simple_list_item_1, childFrom,
childTo);
elvMain = (ExpandableListView) findViewById(R.id.elvMain);
elvMain.setAdapter(sctAdapter);
}
protected void onDestroy() {
super.onDestroy();
db.close();
}
class MyAdapter extends SimpleCursorTreeAdapter {
public MyAdapter(AllProductsActivity context, Cursor cursor, int groupLayout,
String[] groupFrom, int[] groupTo, int childLayout,
String[] childFrom, int[] childTo) {
super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childFrom, childTo);
}
protected Cursor getChildrenCursor(Cursor groupCursor) {
// gettting cursot by elements for concrete group
int idColumn = groupCursor.getColumnIndex(DatabaseHandler.COLUMN_ID);
return db.getSubCategoryData(groupCursor.getInt(idColumn));
}
}
}
public class DatabaseHandler extends SQLiteOpenHelper {
some code...
//get category where idParent = 1
public Cursor getCategoryData() {
return this.getReadableDatabase().query(TABLE_CATEGORY, null, COLUMN_ID_PARENT + " = "
+ 1, null, null, null, null);
}
//get subCategory where idParent = category.id
public Cursor getSubCategoryData(long categoryID) {
return this.getReadableDatabase().query(TABLE_CATEGORY, null, COLUMN_ID_PARENT + " = "
+ categoryID, null, null, null, null);
}
}