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 7933403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:19:22+00:00 2026-06-03T21:19:22+00:00

According to Android documentation registerForContextMenu can be called multiple times for different views: Registers

  • 0

According to Android documentation registerForContextMenu can be called multiple times for different views:

Registers a context menu to be shown for the given view (multiple views can show the context menu).

I try to use this feature for the following layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/host"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:longClickable="true" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

In the source code I call registerForContextMenu both for the host and the list. Unfortunately, such registration leads to a problem: in the method onContextItemSelected(MenuItem item) I always get null for menu info requested through item.getMenuInfo(). Of course, the long touch is made on a list view item in this use case, so menu item should be normally not null. If I remove registerForContextMenu for the host layout, then menu info is provided correctly in the onContextItemSelected.

I need this multiple registration of the context menu in order to make sure it is shown for touches in any place on the screen (details can be found in another question – here). In brief, the context menu should appear for items and on touches outside any item, and if it is invoked for an item, I need to get the item position.

  • 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-03T21:19:23+00:00Added an answer on June 3, 2026 at 9:19 pm

    It”s not because you are using multiple registerForContextMenu, it’s because you set one on the view that contains the other. So all of them register as coming from the host and not the list.

    And a regular view will have no extra menu info.

    Try turning off focus for the host to let it.fall through to the list. It should still work for the host too, it just won’t grab focus before the list.

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

Sidebar

Related Questions

According to the android documentation : Alternatively, starting with ICE_CREAM_SANDWICH, you can also safely
According to Android documentation, using the .getTime() method in the Android location will return
Can anyone tell me how to make a flexible AppWidgets in Android according to
On the Kindle Fire, as there is no Bluetooth, according to the Android documentation
According to the android Activity Lifecycle, the only callback guaranteed to be called (if
According to the Android documentation, Instrumentation.ActivityMonitor is able to return an Activity that is
According to this answer or the android's documentation there is several ways to get
According to Androids documentation I get the impression, that Android only supports ISO 8601
I've created a WebView-based application according to http://developer.android.com/resources/tutorials/views/hello-webview.html Although I did exactly what was
According to android documentation it has full sqlite support. Does it mean that I

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.