trying to create menu in android but having a error. i am 98% sure my code is right. can some one take a look and let me know if there is a problem they see.

res > menu > main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
     <item
        android:id="@+id/newGame"
        android:title="@string/newGame_Label"
        android:icon="@drawable/ic_clear_normal"
        />

     <item
        android:id="@+id/exitGame"
        android:title="@string/exitGame_Label"
        android:icon="@drawable/ic_clear_normal"
        />

</menu>

in MainActicity.java

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    //Menu - what item should do
    public boolean isOpionsItemSelected(MenuItem item){
        //get id of item which user click
        mHumanCounter = 100;
        if(item.getItemId() == R.id.newGame){
            startNewGame();
            System.exit(0);
        }
        if(item.getItemId() == R.id.exitGame){
            //MainActivity.java
            MainActivity.this.finish(); 
        }
        return true;
    }//end of is options item selected method

problem is that when u click on any item in menu. than nothing happens.

Member Avatar for b1izzard

You need to replace your isOpionsItemSelected method with

 @Override
 public boolean onOptionsItemSelected(MenuItem item){
   //Your logic goes here..
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.