Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arabiaexample.amjad.menubycodetester;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- private int groupId = 1;
- int homeId = Menu.FIRST;
- int profileId = Menu.FIRST + 1;
- int searchId = Menu.FIRST + 2;
- int dealId = Menu.FIRST + 3;
- int helpId = Menu.FIRST + 4;
- int contactUs = Menu.FIRST + 5;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(groupId, homeId, homeId, "Home");
- menu.add(groupId, profileId, profileId, "Profile");
- menu.add(groupId, searchId, searchId, "Search");
- menu.add(groupId, dealId, dealId, "Deal");
- menu.add(groupId, helpId, helpId, "Help");
- menu.add(groupId, contactUs, contactUs, "Contact Us");
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case 1:
- Toast.makeText(this, "Home clicked", Toast.LENGTH_SHORT).show();
- break;
- case 2:
- Toast.makeText(this, "Profile clicked", Toast.LENGTH_SHORT).show();
- break;
- case 3:
- Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
- break;
- case 4:
- Toast.makeText(this, "Deal", Toast.LENGTH_SHORT).show();
- break;
- case 5:
- Toast.makeText(this, "Help", Toast.LENGTH_SHORT).show();
- break;
- case 6:
- Toast.makeText(this, "Contact Us", Toast.LENGTH_SHORT).show();
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement