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

  • SEARCH
  • Home
  • 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 8097731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:51:15+00:00 2026-06-05T21:51:15+00:00

I am trying to create a floating Context Menu when long pressing a button.

  • 0

I am trying to create a floating Context Menu when long pressing a button. I have read all the answer but still, I am driving myself crazy with this. Here it is my code:

R.menu.menu.xml

<?xml version="1.0" encoding="utf-8"?>
    <menu
      xmlns:android="http://schemas.android.com/apk/res/android">

        <item android:id="@+id/MnuOpc1" android:title="Opcion1"
               android:icon="@drawable/ic_launcher"></item>
        <item android:id="@+id/MnuOpc2" android:title="Opcion2"
              android:icon="@drawable/ic_launcher"></item>
        <item android:id="@+id/MnuOpc3" android:title="Opcion3"
              android:icon="@drawable/ic_launcher"></item>

    </menu>

OnCreateContextMenu(…)

    @Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
}

onContextItemSelected(…)

@Override
public boolean onContextItemSelected(MenuItem item) {
    Log.v("Hello...","I got the switch");  

    switch (item.getItemId()) {
    case R.id.MnuOpc1:
        Log.v("Hello...","Option 1");   
        return true;
    case R.id.MnuOpc2:
        Log.v("Hello...","Option 2"); 
        return true;
    default:
        return super.onContextItemSelected(item);
    }

I think all the code above is right but I am missing something when calling at registerForContextMenu:

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    linear = (LinearLayout) findViewById(R.layout.main);
    registerForContextMenu(linear);

I tried with registerForContextMenu(getListView()); but it does not work, I am getting an error from Eclipse. What am I doing wrong?

  • 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-06-05T21:51:17+00:00Added an answer on June 5, 2026 at 9:51 pm

    You said you’re trying to create a context menu for a button, but in your onCreate() you register the context menu to a LinearLayout. Can’t tell if that’s it though without knowing what error you are actually getting.

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

Sidebar

Related Questions

Hi to all I'm trying to create a website for my brother http://labelenne.com but
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying create a RCP Application with Eclipse, but I can't get past the
I am trying to create my first game for android. I currently have a
All, I am trying create a 'to & fro' animation using jquery animate &
I'm trying to create a floating effect using this code over a UIImageView: [UIView
I'm trying to create two floating divs inside of another: <div style=width:100%;height:500px;position:relative;top:15px;> <div style=position:relative;float:left;width:58%;height:100%;left:10px;>
I'm trying to create a very simple 2 column layout with floating div 's
I am trying to create a button inside the caption of a table. It
I'm trying to create a floating header. content area and then a sticky footer.

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.