1

I am trying to get an image on a menu item. But in the tutorial it is using an alphabet to view the menu item. I want to view a button on the click on a button. Currently the code is not working. I am referring to a tutorial. Please guide me to the best way to do it.

My code:

package com.example.androiddemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Switch;
import android.widget.Toast;

public class nextpagejava extends Activity implements OnClickListener{
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nextpage);
    Button bt1 = (Button) findViewById(R.id.btn1);
    bt1.setOnClickListener(this);
  }
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
  }
  public void CreateMenu(Menu m){
    m.setQwertyMode(true);
    MenuItem mItm1 = m.add(0, 0, 0, "Item1");
    {
      mItm1.setAlphabeticShortcut('a');
      mItm1.setIcon(R.drawable.images);
    }
  }
  private boolean MenuChoice(MenuItem item){
    switch(item.getItemId()){
      case 0:
        Toast.makeText(this, "You clicked on item 1", Toast.LENGTH_LONG).show();
        return true;
      }
      return false;
    }
  }
dda
  • 6,030
  • 2
  • 25
  • 34
Anu0042
  • 253
  • 4
  • 12

2 Answers2

0

If you are asking about using Icons for the overflow of an ActionBar, you cannot do this - only text descriptions are available for this action.

Booger
  • 18,579
  • 7
  • 55
  • 72
  • then what does this code do public void CreateMenu(Menu m){ m.setQwertyMode(true); MenuItem mItm1 = m.add(0, 0, 0, "Item1"); { mItm1.setAlphabeticShortcut('a'); mItm1.setIcon(R.drawable.images); } } – AnuRaj Jan 11 '13 at 16:34
  • Images won't show up in the overflow area (top right of the screen). That is the overflow area (in is what I am talking about). Getting icons in the 'menu' display is different. I suggest you search SO, as there are many, many questions about this. – Booger Jan 11 '13 at 16:40
  • Like this one: http://stackoverflow.com/questions/5216603/displaying-icon-for-menu-items-of-action-bar-in-honeycomb-android-3-0/5216625#5216625 – Booger Jan 11 '13 at 16:42
0

Hope you are looking for Adding Image to Menu's. If I understand correct, the below tutorial helps you to do that,

http://tonysilvestri.com/blog/2010/08/25/android-options-menu-with-an-image/

Ramesh Sangili
  • 1,633
  • 3
  • 17
  • 31