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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:50:23+00:00 2026-06-02T17:50:23+00:00

The expected output is that data should be loaded once and then for every

  • 0

The expected output is that data should be loaded once and then for every subsequent scroll. But instead, it is loading all the data in the listview at once.

public class ViewPage extends ListActivity{

ListView lv;
ListAdapter ld;
int size=3;

ArrayList<String> filename = new ArrayList<String>();
Cursor contactcursor;
ArrayAdapter<String> arr_ad;
int contact_column_index;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.mylist);




    String[] proj = { ContactsContract.Contacts.DISPLAY_NAME };
    contactcursor = managedQuery(ContactsContract.Contacts.CONTENT_URI, proj, null, null, null);
    contact_column_index = contactcursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
    lv = (ListView)findViewById(android.R.id.list);
    contactcursor.moveToFirst();
        for(int i=0;i<size;i++)
        {

            filename.add(contactcursor.getString(contact_column_index));
            if(!contactcursor.moveToNext())
                break;
        }

        arr_ad = new ArrayAdapter<String>(ViewPage.this, android.R.layout.simple_list_item_1, filename);
        setListAdapter(arr_ad);


        lv.setOnScrollListener(new EndlessScrollListener());
}

public class EndlessScrollListener implements OnScrollListener {

private int visibleThreshold = size;
private int currentPage = 0;
private int previousTotal = 0;
private boolean loading = true;

public EndlessScrollListener() 
{

}

public EndlessScrollListener(int visibleThreshold) 
{
    this.visibleThreshold = visibleThreshold;
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {
    // TODO Auto-generated method stub



    /*Runnable action = new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        }
    };
    runOnUiThread(action);*/

    Toast.makeText(ViewPage.this, "In" , 1).show();
     if (loading) 
     {
         if (totalItemCount > previousTotal) 
         {
            loading = false;
            previousTotal = totalItemCount;
            currentPage++;
         }
     }
     if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) 
     { 


            for(int i=0;i<size;i++)
            {

                if(!contactcursor.moveToNext())
                    break;


                filename.add(contactcursor.getString(contact_column_index));

            }

            arr_ad.notifyDataSetChanged();

            loading = true;
            Toast.makeText(ViewPage.this,totalItemCount+" "+visibleItemCount+" "+firstVisibleItem+" "+visibleThreshold+" ", 1).show();
     }
}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    // TODO Auto-generated method stub

}

}
}

The onscroll method in the endlessscrolllistener class runs and loads the complete data without even the scrolling being done. Thanx in advance.

  • 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-02T17:50:25+00:00Added an answer on June 2, 2026 at 5:50 pm

    onScroll gets called a lot, execute that logic while scrolling is pretty expensive in my opinion.

    I achieved the goal adding a simple logic to my adapter, check this answer I gave a while ago.

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

Sidebar

Related Questions

I need to have a data output that should generate a serial number by
I expected to see the word test appear in the output once and the
I've got a class outputInterface; that should handle the output (to files) of some
I'm new to C++, and I have a question that should be easy, but
Expected output & output I get in debug mode, and release mode under VS2010,
My LINQ query is not producing the expected output below. Basically, it's the sum
$fr = hammad; $frhammad = nuthing; echo $fr{$fr}; Output: h Whereas the expected output
I expected this to print [b] but it prints [] : $x = abc;
Getting Expected ',' or '{' but found '#44559' error. My code looks like this:
Is it expected behavior that two encodings can map to the same decoding? I'm

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.