in my sqlite db i have one table
Name: category
column name: items (only one column) rows in items column: abc, xyz, etc...
but i dont want to create custom navigation drawer. so i added default navigation drawer activity.
in my DatabaseHandler.java there is a code to retrieve all items in arraylist as follows:
public ArrayList<menu> getAllMenu() {
ArrayList<menu> catList = new ArrayList<menu>();
// Select All Query
String selectQuery = "SELECT * FROM " + CATEGOTY_TABLE_NAME;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
menu menu = new menu();
menu.setItem(cursor.getString(0));
// Adding category to list
catList.add(menu);
} while (cursor.moveToNext());
}
// return category list
return catList;
}
MainActivity.java contains:
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
i have removed all default menu items, because i dont want to put them in xml file. i want to populate them from database.
but the question is, how can i call databasehandler.java to get that array list and put it in navigationmenu
plz help...