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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:33:56+00:00 2026-06-13T10:33:56+00:00

In my android app, I have a listview with an option to delete items

  • 0

In my android app, I have a listview with an option to delete items from it
on the same screen. The delete button lies at the bottom of the list view
and there’s a function written for deleting items and refreshing the list view.
This function is being called in onClick() of the List View.
This is where the problem lies.

In delete button’s onClick I have first made a check for knowing which item to delete –

if (ListView.INVALID_POSITION != mListView.getSelectedItemPosition()) {
 //delete the selected item
}else{
 //do nothing
}

So whenever user touches delete button the focus from list view is removed and we get invalid as the list view position and hence the item is not deleted.

I also tried to store the value of selected item in a constant and update it in list view’s onItemSelected() method and then remove the condition from Delete Button’s onClick
.This works but causes another problem – If the user taps into empty area then focus from list view is removed and it appears that nothing is selected, but if u press delete button and then it deletes the last selected item as it is coming from a constant.

This is the problem I am facing.
Please suggest what to do.

  • 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-13T10:33:57+00:00Added an answer on June 13, 2026 at 10:33 am

    Selection is useful only in keyboard mode, its turned off in touch mode so, getSelectedItemPosition() is not always reliable.

    Read do’s and don’t in this developer blog entry.

    If you want to use a single button, Set ListView choice mode to Single/Mutliple, then, on button click, get the checked items and delete them, refresh ListView after that.

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

Sidebar

Related Questions

I have dynamic listview on my android client app that receive data from remote
I have android app . i should pass the data from android to web
I have a Listview in my Android app, and I want there to be
In my android app I have a Tabhost with a ListView as one of
In my android app I have a search screen. The content is stored in
My android app works on landscape mode. I have a listview that contains some
I'm developing a RSS reader android app. I have a ListView that shows my
I have a ListView in my Android app that is partial clickable.... the first
I have a problem with my android app. I have a ListView and this
I have tried making a listview for a android app like this tutorial .

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.