On pressing menu button , I have 2 options : Add & more. On click of more i have 3 options : Organize ,Export & Exit On click of Organize i want other 5 options.
On click of more i get my submenu. But i want other 5 options on click of organize.How do i proceed???
My code in parts is as follows : XML file-------------------------------
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/more"
android:title="@string/moreMenu"
android:icon="@drawable/icon">
<menu>
<item android:id="@+id/Organize"
android:title="@string/Organize" />
<item android:id="@+id/Export"
android:title="@string/Export" />
</menu>
</item>
<item
android:id="@+id/add"
android:title="@string/addMenu"
android:icon="@drawable/add"/>
</menu>
Java-------------------------
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class ToDoList extends Activity {
Menu menu;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.todolist);
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.layout.categorymenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.more:
Toast.makeText(this, "You pressed more!", Toast.LENGTH_LONG).show();
//(What needs to be done from here)
return true;
case R.id.add:
Toast.makeText(this, "You pressed add!", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
public boolean onPrepareOptionsMenu(Menu menu) {
return true;
}
}