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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:34:42+00:00 2026-05-20T22:34:42+00:00

calling ListView’s setSelection() seems to have a problem. a lot of people ask about

  • 0

calling ListView’s setSelection() seems to have a problem. a lot of people ask about it. there are answers but none is working. ignoring issues of visual affects. here’s a basic scenario that results in unexpected results:

listView.setSelection(5); //listView is a ListView. there are >= 6 items in the list
int sel=listView.getSelectedItemPosition();

you would expect sel==5 but actually it’s -1 (which method didn’t work?)
so is this a bug and if not, what are the rules that govern the setting and retrieval of the selected item?

  • 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-20T22:34:43+00:00Added an answer on May 20, 2026 at 10:34 pm

    If you see in the documentation of setSelection you find this:

    Sets the currently selected item. If
    in touch mode, the item will not be
    selected but it will still be
    positioned appropriately. If the
    specified selection position is less
    than 0, then the item at position 0
    will be selected.

    That way, it makes perfectly sense that it returns -1. The item is not selected even if you run this method when you’re in touch mode, as you most likely are.

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

Sidebar

Related Questions

I have made one custom ListView but it is not calling any onclick listener
i have developed android listview via soap calling is successfully..now i have to click
I have what I think to be an odd problem with listview databinding. I
I have a problem understanding why is my ListActivity and its corresponding listView empty
I Have a problem: i have a button that when i click is calling
If I have a nested ListView, and I'm calling a related table in LinQ,
i need to display some records in listview but when i am calling services
I have a Form with a listview. After calling Form.Show I need to update
Calling the WriteObject Method from a background thread is not possible! Is there a
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need

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.