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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:14:36+00:00 2026-05-25T14:14:36+00:00

The case: I have a ListView with a variable amount of ListItems (e.g. 20).

  • 0

The case:
I have a ListView with a variable amount of ListItems (e.g. 20). At first items 0-6 are visible. The user now scrolls down the list and clicks item nr. 15. A new activity starts, and at some point the user hits the back button. Now item nr. 15 might be at the same position, have had its position changed or have been deleted (Handling the deleted situation is not the problem). The other two situations will have equal behaviour, apart from how the list is re-populated (which is not the problem either).

What I would like to do:
Upon returning to the ListView from item nr. 15, I have saved an ID for the item (using setResult and onActivityResult) and the ListView is re-populated with items. (The item in question, here nr. 15, will always be in the list after re-population)

I then want to scroll the list down to the position of item nr. 15, making item nr. 15 the first visible item in the ListView.

The problem:

  • Using the methods getChildCount() and getChildAt(index) does not
    solve my problem, as the desired item might be out of view (not shown
    in the list, but in the datacore of the listadapter).
  • Using the method getCount() instead of getChildCount() gives me the right number of items in the list – but as soon as I run through the items in a for-loop I run into a NullPointerException when index >= getChildCount().

My question:

  • How can I run through all items (visible in list or not) and when I find the item that meets my requirements, scroll the listview making that item the first visible 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-25T14:14:36+00:00Added an answer on May 25, 2026 at 2:14 pm

    You could iterate over your ListAdapter using int getCount() and Object getItem(int position) until you find the object with your desired ID, then use the current position as argument to ListView.smoothScrollToPosition(int position).

    Not very efficient but should have the desired effect.

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

Sidebar

Related Questions

I have a ListView with ViewSwitcher items. The goal is to tap a list
I have a case that keeps coming up where I'm using a ListView or
I want to have a border around ListViewItem (row in my case). ListView source
I have a listview where each list item can contain 1 or more clickable
In my app I have a listview with news items showing only a summary,
My activity implements OnTouchListener and it have one ListView inside it. When user touch
In my case, I have a ListView which contains two kinds of views, folders
Basically, I have a ListView of items. When one is selected, a text box
Basically, I have 2 ListView's each binding to a different ItemsSource . List 1
I have a ListView with onItemClick() method . Now I want to detect a

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.