Sayem Siam
Sayem Siam

Reputation: 199

OptionMenu does not show....

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // mEditor=(TextView)findViewById(R.id.text);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);

        Log.d("sayem", "onCreateOptionMEnu");

        return true;

    }

My XML file:

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="schemas.android.com/apk/res/android"; >
<item android:id="@+id/settings" 
android:title="@string/settings_label" 
android:visible="true" 
android:alphabeticShortcut="@string/settings_shortcut" 
android:icon="@drawable/violet" /> 
</menu>

Upvotes: 0

Views: 268

Answers (2)

Pawan
Pawan

Reputation: 1523

take a look link1 or link2. Or if don't want to inflate menu.xml, you can do this :

Try the following one, you don't need to inflate xml in this.

package com.menusample;

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

public class MenuSampleActivity 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) {

    //menu.add(int groupId,int itemId,int orderId, Charsequence title); 
        menu.add(0, 0, 0, "title1");
        menu.add(0, 1, 1, "title2");
        menu.add(0, 2,2, "title3");
        menu.add(0, 3, 3, "title4");

        return super.onCreateOptionsMenu(menu);
    }
}

Upvotes: 2

Bryan
Bryan

Reputation: 3667

The only difference that I can see in the code from my code is that in your XML file, the line

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

has a semi-colon at the end.

Mine does not, and the example from Android, at http://developer.android.com/guide/topics/ui/menus.html, does not have a semi-colon either.

The line of code should look like this:

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

Upvotes: 0

Related Questions