I have a database with about 12000 records which I want to load in a ListView. I'm using BaseAdapter. When I load items in ListView, It's taking so long.
Is there any way to reduce this time, for example I have seen an app that loads only limited numbers of items until the scroll bar reaches the end of ListView, then it loads again more items.
Asked
Active
Viewed 8,182 times
1
-
set a limit from your query like you said http://stackoverflow.com/questions/1407442/android-sqlite-and-huge-data-sets – tyczj Jul 26 '13 at 20:15
2 Answers
1
This may be useful, a ListView
with load More button:
http://www.androidhive.info/2012/03/android-listview-with-load-more-button/
You can also take a look here:

Community
- 1
- 1

amatellanes
- 3,645
- 2
- 17
- 19
0
You should set onScrollListener in your list and keep a track of the visibility of the items and the offset. I show you an example here:
// Adapter for the custom list
adapter = new Adapter(this, activityList);
setListAdapter(adapter);
registerForContextMenu(getListView());
getListView().setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView lw, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount) {
switch(lw.getId()) {
case android.R.id.list:
// Make your calculation stuff here. You have all your
// needed info from the parameters of this function.
// Sample calculation to determine if the last
// item is fully visible.
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount) {
// Last item is fully visible.
Log.i("a", "last item fully visible...");
try {
if(offset > 0){
int newLimit;
int oldOffset = offset;
if(offset >= limit){
newLimit = limit;
offset = offset - limit;
}
else{
newLimit = length;
offset = 0;
}
for (int i=0; i < newLimit; i++)
{
JSONObject item = jFeed.getJSONObject(i + length - oldOffset);
// Pulling items from the array
// Get list info
String sInfo = item.getString(TAG_INFO);
Log.i(MainActivity.class.getName(), "Info: " + sInfo);
// Populate the dynamic custom list
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_INFO, sInfo);
activityList.add(map);
}
adapter.notifyDataSetChanged();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
if(scrollState == 0)
Log.i("a", "scrolling stopped...");
}
});

Julian Mancera
- 194
- 1
- 12