Posted By

variable3 on 05/03/11


Tagged


Versions (?)

Option Menu Example


 / Published in: Java
 

  1. //MainActivity.java
  2. public boolean onCreateOptionsMenu(Menu menu) {
  3. MenuInflater inflater = getMenuInflater();
  4. inflater.inflate(R.menu.main, menu);
  5. return true;
  6. }
  7.  
  8. @Override
  9. public boolean onOptionsItemSelected(MenuItem item) {
  10. switch (item.getItemId()) {
  11.  
  12. case R.id.list_users:
  13. Intent a = new Intent(HomeActivity.this, ListsUsersActivity.class);
  14. startActivity(a);
  15. break;
  16. case R.id.add_city:
  17. Intent b = new Intent(this, AddCityActivity.class);
  18. startActivity(b);
  19. break;
  20. case R.id.exit:
  21. Intent c = new Intent(this, HomeActivity.class);
  22. startActivity(c);
  23. break;
  24. }
  25.  
  26. return true;
  27. }
  28. //menu.xml<?xml version="1.0" encoding="utf-8"?>
  29. <menu xmlns:android="http://schemas.android.com/apk/res/android">
  30. <item android:id="@+id/list_users" android:title="List Users" />
  31. <item android:id="@+id/add_city" android:title="Add City" />
  32. <item android:id="@+id/exit" android:title="Exit" />
  33. </menu>

Report this snippet  

You need to login to post a comment.