Create OptionsMenu in /res/menu/menu.xml

Create OptionsMenu in /res/menu/menu.xml

/workspace/OptionsMenu/res/menu/menu.xml
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/opt1"
android:title="Option 1" />
<item android:id="@+id/opt2"
android:title="Option 2" />
<item android:id="@+id/opt3"
android:title="Option 3" />
<item android:id="@+id/opt4"
android:title="Option 4" />
<item android:id="@+id/opt5"
android:title="Option 5" />
</menu>


/workspace/OptionsMenu/src/com/OptionsMenu/OptionsMenu.java
package com.OptionsMenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class OptionsMenu 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
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case (R.id.opt1):
break;
case (R.id.opt2):
break;
case (R.id.opt3):
break;
case (R.id.opt4):
break;
case (R.id.opt5):
break;
}
return true;
}
}


Related Post:
- Overwrite MENU key to create custom menu

0 Response to "Create OptionsMenu in /res/menu/menu.xml"

Posting Komentar