# Add New

Here the instructions to add new category :&#x20;

### SERVER

1\. Open the\_city database at **phpmyadmin** panel, and open table **category**\
2\. Default category list we give is 10 item :

<div align="left"><img src="https://850775592-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGFwKX8ikta8ft7T6Oq%2F-LHxAOSEntwHpVGmkpiF%2F-LHxBynCz4QeiBdA-ags%2Fimage_2.jpg?alt=media&#x26;token=6803698c-1f18-4a36-aed9-8747796c974f" alt=""></div>

3\. Insert new category item, by execute this query :&#x20;

```
 INSERT INTO category (cat_id, name) VALUES (11, 'New Category');
```

* **11** ---> id new category
* **'New Category'** ---> name new category

<div align="left"><img src="https://850775592-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGFwKX8ikta8ft7T6Oq%2F-LHxAOSEntwHpVGmkpiF%2F-LHxC8k6jAl39TfMNBRu%2Fimage_3.jpg?alt=media&#x26;token=42613066-c14c-43fe-87eb-13880a8c95f5" alt=""></div>

### ANDROID

1\. Update Sqlite Database  -- > Open file res/values/**category.xml**

```markup
<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

&#x20;2\. Add Drawer Menu String Title -- > Open file res/values/**strings.xml**&#x20;

```markup
    <!-- ==================== 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

&#x20; 3\. Add Drawer Menu -- > Open file res/menu/**menu\_drawer.xml**&#x20;

```markup
 <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>
```

* &#x20;       **\<item**
* &#x20;           **android:id="@+id/nav\_new\_category"**
* &#x20;           **android:icon="@drawable/ic\_nav\_new\_category"**       &#x20;
* &#x20;           **android:title="@string/title\_nav\_new\_category" />    ---->** item menu drawer

4\. Add Map Menu Category --> Open file res/menu/**menu\_activity\_maps.xml**

```markup
<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>
```

* &#x20;       **\<item**
* &#x20;           **android:id="@+id/nav\_new\_category"**    &#x20;
* &#x20;           **android:title="@string/title\_nav\_new\_category" />    ---->** item menu drawer

&#x20; 5\. Open file java/app/thecity/**ActivityMain.java** open method&#x20;

```java
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**:
* &#x20;   fragment = new FragmentCategory();
* &#x20;   bundle.putInt(FragmentCategory.TAG\_CATEGORY, **cat\[10]**);
* &#x20;   break;

**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**&#x20;

1. **data at table Category**

**#Android**

1. res/values/**category.xml**
2. res/values/**strings.xml**
3. res/menu/**menu\_drawer.xml**
4. res/menu/**menu\_activity\_maps.xml**
5. java/app/thecity/**ActivityMain.java**
6. java/app/thecity/**ActivityMaps.java**

Add New Category Done :)
