Question

I have a ListView that is populated from a SQLite database. The database is 300,000+ rows and the listview is populated after searching from different things(e.g, name, surname, age and other general database stuff).

It works fine for small search returns but if the search returns over 2,000 results then the app freezes and stops.

What I want to do is to return 100 results from the database, then when it scrolls to the bottom of the list it goes back to the cursor and loads another 100. I have got a dynamic list working but it still freezes because it still searching for 1000+ results and just showing 100 results. This is some pseudo code (as the listview is 500+ lines, there are tonnes of if else statements depending on what is searched)

    public class example extends Activity implements OnScrollListener{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.showlist);
        //It opens database here
        ListView list = (ListView) findViewById(R.id.listView1);
            if(nameOnly is searched){
                //adds data to list with array adapter here
                //return 100 results and put it in a list
            }else if(name and surname is searched){
                //adds data to list with array adapter here
                //return 100 results and put it in a list
            }else if (surname only searced){
                //adds data to list with array adapter here
                //return 100 results and put it in a list
            }
    }
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, 
    int visibleItemCount,     int totalItemCount) {
    boolean load = firstVisibleItem+visibleItemCount>=totalItemCount;
    if(load){
        //This is where i want to set it to return 
    //the next 100 and add it to the list from the if else statements
    }       
}
@Override
public void onScrollStateChanged(AbsListView arg0, int arg1) {
}   
    }

So I want to tried was to the cursor again in the OnScroll and use OFFSET in the SQLite cursor but it didn't work. I don't now if this is the best way to do it so any ideas are appreciated!

Was it helpful?

Solution

As you have lots of record, you have some choices which you can make. You can use async task to load the record or load more facility.

For load more you can check out following link List with load more

Also you can check out async task Async task

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top