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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:05:00+00:00 2026-05-22T00:05:00+00:00

I need to handle the selected row in listview on long click on the

  • 0

I need to handle the selected row in listview on long click on the row but because am using menus I can’t override the onclicklistener. I am trying to do this:

listView.setOnLongClickListener(new OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        taskPosition = listView.getSelectedItemPosition();
        return true;
    }
});

but it doesn’t work. Can anyone help me?

  • 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-22T00:05:01+00:00Added an answer on May 22, 2026 at 12:05 am

    i got the value of listView.getSelectedItemPosition(); is equal -1

    Of course. Rows typically are not selected. Rows are only selected if the user is using a pointing device (D-pad, trackball, etc.).

    i need to handle the selection longclick on listview and use it in onContextItemSelected to perform action

    No, you don’t. You either use context menus or you use a long-click listener with a widget. You do not use both.

    If you are trying to determine what row was long-clicked from onContextItemSelected(), here is a sample project that will demonstrate that for you, if your adapter is an ArrayAdapter. If you are using a CursorAdapter, here is a different sample project that will demonstrate this for you.

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

Sidebar

Related Questions

I need to handle strings in my php script using regular expressions. But there
I need to handle events of two different types but I'm running into the
I'm using IIS7 and ASP.NET. Basically building a simple CMS and need to handle
I am using Listview,the View selected is largeicon mode. The problem i am facing
I'm trying to handle mouse clicks in an application, but the logic is becoming
I am using asp.net membership and trying to update a users details but get
I am trying to mimic the way a ListView and other controls handle SelectedItems
For a project I need to handle audio in an iPhone app quite special
I'm writing a batch (.bat) script and I need to handle the case in
I have a problem with NCurses ... i need to handle all keys like

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.