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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:32:36+00:00 2026-05-28T04:32:36+00:00

I want to show the items queried from database in the listview with SimpleCursorAdapter.

  • 0

I want to show the items queried from database in the listview with SimpleCursorAdapter.
For example, there may be 20,000 items in the database. I want to just load 100 items(_id : 1-100) queried instead of load all items, when scrolling in the end of listview, load another 100 items(_id : 101-200) queried, how to achieve it? Any suggestion is welcome, thanks.

Relative codes are as follows:

protected void onCreate(Bundle savedInstanceState) {
    mCursor = managedQuery(CONTENT_URI, PROJECTION, null, null, "_id DESC");
    mAdapter = new SimpleCursorAdapter(this,R.layout.list_content,  mCursor, keys,  values);
    setListAdapter(mAdapter);
}

In my defined listview, i want to load more items by query database.

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) 
{
    int lastItem = firstVisibleItem + visibleItemCount - 1;

    if (mListAdapter != null) {
        if ((lastItem == mListAdapter.getCount()-1) && (mRefreshState != REFRESHING)) {
            mFooterView.setVisibility(View.VISIBLE);
            mRefreshState = REFRESHING;
            new Handler().postDelayed(new Runnable() {  
                public void run() {  
                    //execute the task ,  i want to load more items by query database
                    RefreshListView(LOADING_STORED_INFO);                                           
                }  
             }, DEFAULT_DELAY_TIMER);           
        }
    }
}

In the AsyncTask loading data, i do the query operation.

    protected Integer doInBackground(Integer... params)
    { 
        Uri uri = ContentUris.withAppendedId(CONTENT_URI, mCursor.getInt(0)-1);
        cursor = managedQuery(uri, PROJECTION, null, null, "_id DESC");
        return (0 == params[0]) ? 1 : 0;
    }

    @Override
    protected void onPostExecute(Integer result)
    {
        mAdapter.changeCursor(cursor);//is this OK?
        mAdapter.notifyDataSetChanged();
        /*
        if (1 == result)
        {
            mListView.setSelection(1);
        }
        else
        {
            mListView.setSelection(mCount-1);               
        }*/
        // Call onRefreshComplete when the list has been refreshed.
        mListView.onRefreshComplete(result); 
        super.onPostExecute(result);
    } 
  • 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-28T04:32:37+00:00Added an answer on May 28, 2026 at 4:32 am

    Use the LIMIT statement in the SQL query in this way:

    SELECT your_column FROM your_table ORDER BY your_order LIMIT limit_skip, limit_count
    

    Then you can use a OnScrollListener to retrieve the index of the first visible cell and the number of visible cells so you can increment limit_skip and limit_count coherently.

    Instead of the generic AsyncTask use a CursorLoader and implement LoaderManager.LoaderCallbacks<Cursor> as follow:

    public Loader<Cursor> onCreateLoader(int id, Bundle args){
        String orderBy = "_id DESC"
        if(args != null){
            orderBy += " LIMIT " + args.getInt("LIMIT_SKIP") + "," + args.getInt("LIMIT_COUNT");
        }
    
        return new CursorLoader(this /*context*/, CONTENT_URI, PROJECTION, null, null, orderBy);
    }
    
    public void onLoadFinished(Loader<Cursor> loader, Cursor data){
        listAdapter.swapCursor(data);
    }
    
    public void onLoaderReset(Loader<Cursor> loader){
        listAdapter.swapCursor(null);
    }
    

    Then, in onCreate(), pass null as cursor to new SimpleCursorAdapter() and create the CursorLoader in this way:

    getLoaderManager().initLoader(0, null, this /*LoaderCallbacks<Cursor>*/);
    

    Then, in onScroll(), reset everytime the loader in this way:

    Bundle args = new Bundle();
    args.putInt("LIMIT_SKIP", limit_skip_value);
    args.putInt("LIMIT_COUNT", limit_count_value);
    getLoaderManager().restartLoader(0, args, this /*LoaderCallbacks<Cursor>*/);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show 100 items from Azure table, I already know PartitionKey and
i want to show a my Popover with a TableView just from the beginning,
I have a ListBox which displays items of variable height. I want to show
I want to show HTML content inside Flash. Is there some way to do
I have an issues, I want to show 20 items in the list. But
I want to show items in my gridview as a 5 across and a
I have an ArrayList and want to show items present in the arraylist inside
I have an unordered list of 50 items. I want to show only 10
I have a ListView bound to a collection of items. I do not want
I have a Gridview with a list of Items. I want to show the

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.