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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:39:10+00:00 2026-06-14T22:39:10+00:00

Possible Duplicate: Android: using notifyDataSetChanged and getLastVisiblePosition – when the listView is actually updated?

  • 0

Possible Duplicate:
Android: using notifyDataSetChanged and getLastVisiblePosition – when the listView is actually updated?

I have a simple ListView with only a few entries. Depending on the device size and orientation, the ListView needs to scroll or not.

I have also a picture on the screen, which is not really necessary. I would like to remove the picture if there is not enough space for the ListView without scrolling.

When I fill my ListView in the onCreate of the activity, the getLastVisiblePosition() is not yet valid, it returns -1. Thus I can not compare last visible item to list count.

int lastVisiblePos = listView.getLastVisiblePosition(); // returns -1

(If I click on a button later to recheck, the value is correct.)

Using the onScrollingListener is too late, as the picture should not be shown in the first place.

I am developing on API level 10.

Any suggestions?

  • 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-14T22:39:11+00:00Added an answer on June 14, 2026 at 10:39 pm

    Compare getLastVisiblePosition() with getCount() in a Runnable to see if the entire ListView fits on the screen as soon as it has been drawn. You should also check to see if the last visible row fits entirely on the screen.

    Create the Runnable:

    ListView listView;
    Runnable fitsOnScreen = new Runnable() {
        @Override
        public void run() {
            int last = listView.getLastVisiblePosition();
            if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) {
                // It fits!
            }
            else {
                // It doesn't fit...
            }
        }
    };
    

    In onCreate() queue your Runnable in the ListView’s Handler:

    listView.post(fitsOnScreen);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Android Unknown Command 'crunch' I have been using eclipse just fine but
Possible Duplicate: How to refresh Android listview? I am looking for using Refresh button
Possible Duplicate: Android Toast started from Service only displays once I'm using Service Android
Possible Duplicate: Andriod: Inflate listview using its android:id With regard to the following qn
Possible Duplicate: Slow Android emulator I am using Eclipse to load the Android project
Possible Duplicate: Best XML Parser for PHP Using JAXB with Google Android I need
Possible Duplicate: Where does Android emulator store SQLite database? I am using SQLite and
Possible Duplicate: Separate Back Stack for each tab in Android using Fragments I've recently
Possible Duplicate: Android ListView with delete button android Listview button Okay .. I will
Possible Duplicate: Can we post image on twitter using twitter API in Android? I

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.