Here the instructions to add new category :
SERVER
1. Open the_city database at phpmyadmin panel, and open table category
2. Default category list we give is 10 item :
3. Insert new category item, by execute this query :
INSERT INTO category (cat_id, name) VALUES (11, 'New Category');
'New Category' ---> name new category
ANDROID
1. Update Sqlite Database -- > Open file res/values/category.xml
<resources>
<integer-array name="id_category">
. . .
<item>9</item>
<item>10</item>
<item>11</item> <!--New Category Id-->
</integer-array>
<string-array name="category_name">
. . .
<item>Public Services</item>
<item>Money</item>
<item>New Category</item> <!--New Category Name-->
</string-array>
<integer-array name="category_icon">
. . .
<item>@drawable/ic_nav_public</item>
<item>@drawable/ic_nav_money</item>
<item>@drawable/ic_new_category</item> <!--New category Icon-->
</integer-array>
</resources>
<item>11</item> ---> id new category
<item>New Category</item> --> name new category
<item>@drawable/ic_new_category</item> --> new icon category
2. Add Drawer Menu String Title -- > Open file res/values/strings.xml
<!-- ==================== Strings related to Drawer Menu =========================== -->
. . .
<string name="title_nav_public">Public Services</string>
<string name="title_nav_money">Money</string>
<string name="title_nav_new_category">New Category</string>
<string name="title_nav_new_category">New Category</string> ---> String for title drawer menu
3. Add Drawer Menu -- > Open file res/menu/menu_drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
. . .
. . .
<item
android:id="@+id/nav_money"
android:icon="@drawable/ic_nav_money"
android:title="@string/title_nav_money" />
<item
android:id="@+id/nav_new_category"
android:icon="@drawable/ic_nav_new_category" --> must add icon into drawable
android:title="@string/title_nav_new_category" />
</group>
</menu>
android:id="@+id/nav_new_category"
android:icon="@drawable/ic_nav_new_category"
android:title="@string/title_nav_new_category" /> ----> item menu drawer
4. Add Map Menu Category --> Open file res/menu/menu_activity_maps.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
...
...
<menu>
<item
android:id="@+id/nav_all"
android:title="@string/title_nav_all"
app:showAsAction="never" />
<item
android:id="@+id/nav_new_category"
android:title="@string/title_nav_new_category"
app:showAsAction="never"/>
...
...
</menu>
</item>
</menu>
android:id="@+id/nav_new_category"
android:title="@string/title_nav_new_category" /> ----> item menu drawer
5. Open file java/app/thecity/ActivityMain.java open method
public boolean onItemSelected(int id) {
. . .
switch (id) {
. . .
case R.id.nav_money:
fragment = new FragmentCategory();
bundle.putInt(FragmentCategory.TAG_CATEGORY, cat[9]);
break;
case R.id.nav_new_category:
fragment = new FragmentCategory();
bundle.putInt(FragmentCategory.TAG_CATEGORY, cat[10]);
break;
default:
break;
}
}
Handle when drawer menu click
case R.id.nav_new_category:
fragment = new FragmentCategory();
bundle.putInt(FragmentCategory.TAG_CATEGORY, cat[10]);
nav_new_category --> menu id from menu_drawer.xml
cat [10] --> gain id new category from array of integer at category.xml
6. Open java/app/thecity/ActivityMaps.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
. . .
} else {
String category_text;
if (item.getItemId() != R.id.menu_category) {
category_text = item.getTitle().toString();
switch (item.getItemId()) {
case R.id.nav_all:
cat_id = -1;
break;
case R.id.nav_new_category:
cat_id = cat[10];
break;
. . .
}
. . .
}
}
return super.onOptionsItemSelected(item);
}
CHANGED FILE
#Server
#Android
res/menu/menu_activity_maps.xml
java/app/thecity/ActivityMain.java
java/app/thecity/ActivityMaps.java
Add New Category Done :)