Wednesday 26 December 2012

MenusDemo

OUTPUT:



package com.venkool.menu;

import android.app.Activity;


public class MenuDemoActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

      }

      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
            // TODO Auto-generated method stub

            menu.add(1, 1, 1, "chat");
            menu.add(1, 2, 2, "Connect");
            menu.add(1, 3, 3, "search");

            menu.add(2, 4, 4, "Edit");
            menu.add(2, 5, 5, "Save");
            menu.add(2, 6, 6, "Exit");

            return super.onCreateOptionsMenu(menu);
      }

      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub

            if (item.getItemId() == 1) {
                  Toast.makeText(this, "Chat", 5000).show();
            }
            if (item.getItemId() == 2) {
                  Toast.makeText(this, "Connect", 5000).show();
            }
            if (item.getItemId() == 3) {
                  Toast.makeText(this, "search", 5000).show();
            }
            if (item.getItemId() == 4) {
                  Toast.makeText(this, "my", 5000).show();
            }
            if (item.getItemId() == 5) {
                  Toast.makeText(this, "Save", 5000).show();
            }
            if (item.getItemId() == 6) {
                  Toast.makeText(this, "Exit", 5000).show();
            }

            return super.onOptionsItemSelected(item);
      }
}

No comments:

Post a Comment