Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:48:34+00:00 2026-05-24T17:48:34+00:00

I am using the following method to add a ContextMenu to a custom view

  • 0

I am using the following method to add a ContextMenu to a custom view i have built but i want to know how to react to the press of that contextmenu.

This is not an Activity so i cannot do this:

  @override
  public boolean onOptionsItemSelected(MenuItem item) {

Here is the code

 private View.OnCreateContextMenuListener vC = new View.OnCreateContextMenuListener() {

    @Override
    public void onCreateContextMenu(ContextMenu arg0, View arg1,
            ContextMenuInfo arg2) {
        // TODO Auto-generated method stub
        arg0.add(0, 0, 0, "Call");
        arg0.add(0, 1, 0, "Map");
        arg0.add(0, 2, 0, "Market");


    }


};

Update:

Here is a very simplified verion of my class.

 public final class NewView extends View {



 public NewView(Context context, AttributeSet attrs) {
    super(context, attrs);
    cntxt = context;
    this.setLongClickable(true);
    this.setOnLongClickListener(vLong);
    this.setOnCreateContextMenuListener(vC);


 }

private View.OnLongClickListener vLong = new View.OnLongClickListener() {
    public boolean onLongClick(View view) {
        showContextMenu();
             return true;   
    }
 };  
 private View.OnCreateContextMenuListener vC = new View.OnCreateContextMenuListener() {

    @Override
    public void onCreateContextMenu(ContextMenu arg0, View arg1,
            ContextMenuInfo arg2) {
        // TODO Auto-generated method stub
        arg0.add(0, 0, 0, "Call");
        arg0.add(0, 1, 0, "Map");
        arg0.add(0, 2, 0, "Market");


    }

};


  } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:48:35+00:00Added an answer on May 24, 2026 at 5:48 pm

    Use item.getItemId() and create switch and cases based on the number returned by getItemId()

    Something like this.

     @override
      public boolean onOptionsItemSelected(MenuItem item) {
    
          switch(item.getItemId())
          {
             case 1:
                   Log.i("FIRST ITEM: ", "CALL");
                   break;
             case 2: 
                    Log.i("2nd ITEM: ", "MAP");
                    break;
              case 3:
                   Log.i("3rd ITEM: ", "Market");
                   break;
             default:
          }
    }
    

    I hope this is what you meant by reacting on menu items selection. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial that renders a select box using the following method: <%=
I am using the following method: set_browser_log_level 'off' but my log level continues to
I'm using the following method to add a new row in my table: [tableView
I have a WCF service that calls the following method in one of my
I'm new and this is probably very trivial but I have the following method
I'm using following rules to validate the username using jQuery validation method. I want
I add hover images to .Net LinkButtons using the following method: .rollover a {
I have populated datagridview using the following method and I have added button column
I have the following method GetData that creates a StreamReader from a file. private
I'm using the following method to send mail from Python using SMTP. Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.