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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:16:34+00:00 2026-05-15T06:16:34+00:00

I have read on this site that it is necessary to customize the setOnItemSelectedListener

  • 0

I have read on this site that it is necessary to customize the setOnItemSelectedListener and setOnItemClickListener of a ListView if we want to know the Index of the SelectedItem (.getSelectedItemPosition()). So that is what I do but it does not stores the position of the SekectedItem, instead i have always -1…

What I want to do is just to give the user a way to delete items from a list by selected and Item and Clicking a button.

See the code below :

    listViewPeople.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int i, long l) {
            try {
                // Remembers the selected Index
                listViewPeopleId = listViewPeople.getSelectedItemPosition();
            }
            catch(Exception e) {
                System.out.println("Nay, cannot get the selected index");
            }
        }
    });

    listViewPeople.setOnItemSelectedListener(new ListView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> a, View v, int i, long l) {
            try {
                // Remembers the selected Index
                listViewPeopleId = listViewPeople.getSelectedItemPosition();
                System.out.println("Yay, set the selected index " + listViewPeopleId);
            }
            catch(Exception e) {
                System.out.println("Nay, cannot get the selected index " + listViewPeopleId);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            try {
                // Remembers nothing selected
                listViewPeopleId = -1;
                System.out.println("Yay, set that nothing is selected " + listViewPeopleId);
            }
            catch(Exception e) {
                System.out.println("Nay, cannot set that nothing is selected " + listViewPeopleId);
            }
        }
    });

What’s wrong??

Thank you for your help!

Christophe

  • 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-15T06:16:35+00:00Added an answer on May 15, 2026 at 6:16 am

    Instead of doing listViewPeople.getSelectedItemPosition(); try using the int i parameter to get the index.

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

Sidebar

Related Questions

I have read somewhere on this site or CodeProject that good rule is if
I've been trying for hours and have read what this site and the internet
I have read a number of questions on this site about this issue, I
Ok so, i have this site that i am putting together in the play
I have read this question and the simple and clear answer but it's not
I have read this thread when I got the the git: command not found
I have read this question but it's not quite what I was looking for.
I have read this article from High Scalability about Stack Overflow and other large
I have read this article about 400% boost of your website . This is
I have read this. Jquery checkbox <input type=checkbox name=checkGroup id=all> <input type=checkbox name=checkGroup id=one

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.