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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:57:30+00:00 2026-06-12T22:57:30+00:00

I want to put a context menu on a listview. This seems very simple

  • 0

I want to put a context menu on a listview. This seems very simple to do but I am getting some interesting behavior. The listview has two fields, a textview and an editText. The long press opens up the menu on the EditText but nowhere else on the listview.
Here are the pieces of code.

public class ManageClass extends ListActivity {

super.onCreate(savedInstanceState);
    setContentView(R.layout.manageclass);

      //Tons of not relevant stuff that I would be happy to provide.
                    pfdata = new PortfolioData(this);
            try {
        Cursor cursor = getClasses();
        showClasses(cursor);

    } finally {
        pfdata.close();
    }
}

  private Cursor getClasses() {

    String sql = "select c._id, c.NAME as NAME , c.percentage as PERCENTAGE "
            + "from asset_classes c;";

    SQLiteDatabase db = pfdata.getReadableDatabase();

    Cursor cursor = db.rawQuery(sql, null);
    startManagingCursor(cursor);
    return cursor;

}

private void showClasses(Cursor cursor) {

    adapter = new MySimpleCursorAdapter(this, R.layout.classrow, cursor,
            FROM, TO, t);

    // Log.d("TEST", Integer.toString(adapter.getCount()));

    setListAdapter(adapter);
    adapter.notifyDataSetChanged();
                //I've tried moving this line around but it hasn't made a difference.
    registerForContextMenu(getListView());
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
    ContextMenuInfo menuInfo) {


      menu.add(Menu.NONE, 0, 0, "A");
      menu.add(Menu.NONE, 1, 1, "B");
      menu.add(Menu.NONE, 2, 2, "C");

}

Lastly, the layout itself which I admit is overly complicated

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/editText1"
        android:layout_width="300px"
        android:layout_height="wrap_content"
        android:text="@string/TCLabel" />

    <TextView
        android:id="@+id/classtotalpercentage"
        android:layout_width="109dp"
        android:layout_height="wrap_content"
        android:textSize="50px" />
</LinearLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/AddClassLabel"
        android:layout_width="200px"
        android:layout_height="wrap_content"
        android:layout_weight="0.38"
        android:text="@string/AddClassLabel" />

    <Button
        android:id="@+id/addclass_button"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:text="@string/addclassbutton_label" />
</LinearLayout>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/grey"
    android:orientation="horizontal"
    android:padding="10sp" >

    <TextView
        android:id="@+id/assetclassHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/assetclassHeader"
        android:width="200dp" />

    <TextView
        android:id="@+id/percentageHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/assetclassHeader"
        android:text="@string/percentageHeader"
        android:width="100dp" />
</LinearLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:fadeScrollbars="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical" />

    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_list_data" />
</RelativeLayout>

</LinearLayout>

I appreciate any advice. I would like the menu on the textview and not the edittext, if possible.

An update. I have found that it has something to do with the EditText. If I change it to a textview or remove it alltogether, then everything works as it should.

  • 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-12T22:57:31+00:00Added an answer on June 12, 2026 at 10:57 pm

    I had a similiar problem with checkboxes and found the issue was caused by the checkbox getting the focus. I changed the attribue to:
    android:focusable=”false”

    and it now works correctly.

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

Sidebar

Related Questions

I want to put some images in an area at the application start. As
I'm very new at CSS and i want to put a header on to
I'm using JQuery Mobile 1.2.0 version. I want to put some html code in
I have an custom module for search location.Now i want to put this module
I'm trying to create a custom search but getting stuck. What I want is
I have this context menu resource: <ResourceDictionary xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <ContextMenu x:Key=FooContextMenu> <ContextMenu.CommandBindings> <CommandBinding Command=Help
I have put together some code from various sources but javascript is somewhat unknown
Im localizing my GWT app, and I want to localize the context menu in
How can I modify a GWT menu - grey out some entries, put a
I want to put a form in my menu to be able to choose

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.