Thursday, September 22, 2011

How to create an option menu (F2)



package co.cc;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class ContextMenu 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
     super.onCreateOptionsMenu(menu);
     createMenu(menu);
     return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
     // TODO Auto-generated method stub
     return MenuChoice(item);
    }
    private void createMenu(Menu menu) {
     MenuItem mni1 = menu.add(0, 0, 0, "About");
     {
      mni1.setAlphabeticShortcut('a');
      mni1.setIcon(R.drawable.about);
     }
     MenuItem mni2 = menu.add(0, 1, 1, "Exit");
     {
      mni2.setAlphabeticShortcut('x');
      mni2.setIcon(R.drawable.exit);
     }

    }
    private boolean MenuChoice(MenuItem item) {
     switch (item.getItemId()) {
  case 0:
   setContentView(R.layout.about);
   return true;
  case 1:
   super.finish();
   return true;
  }
     return false;
    }
}




F2 display menu context option

android-menu-option(f2)

Click About display content about

about

Link Download
http://www.ziddu.com/download/16472331/ContextMenuAndroid.rar.html

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.