I want to show the items requested from a database in a list using SimpleCursorAdapter. For example, a database may have 20,000 items. I just want to load the 100 elements (_id: 1-100) requested instead of loading all the elements, while scrolling at the end of the list, load another 100 elements (_id: 101-200), how to achieve them? Any suggestion is welcome, thanks.
Relative Codes:
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 specific view, I want to load more elements into the query base.
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() {
In AsyncTask boot data, I perform a 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);
android cursor simplecursoradapter
breeze
source share