pardom-zz / ActiveAndroid

Active record style SQLite persistence for Android
http://www.activeandroid.com
4.7k stars 1.03k forks source link

How to get data from ActiveAndroid to support ListView virtualization #236

Open nologinatgit opened 10 years ago

nologinatgit commented 10 years ago

As far as I know, Android listview shows the data virtualized (meaning it loads only the visible ones), so it is fast as it can be.

I have lots of data to get from the database (around 2000 but with lots of data in the fields), and I use ActiveAndroid in an AsyncTask to get them.

Unfortunately the AsyncTask with AA takes around 10-15 seconds to get the data so I see a progressbar during that time.

I get his by this code:

  LocalDateTime start=new LocalDateTime();
  LogCat("Start: "+start);
     elements = new Select().from(Data.class)
        .where("Data_Id=?", DataId).orderBy("Name ASC").execute();

  LogCat("Elements: "+elements .size());
  LocalDateTime end=new LocalDateTime();
  LogCat("End: "+end);
  LogCat("Time: "+(new Period(start,vege).getSeconds()+" s"));

It would be good to accelerate the loading by somehow virtualizing the data retrieval.

I also use a search in the listview, that searches the whole list. So considering the would be also good.

What do you suggest? How should I proceed?

SleeplessByte commented 10 years ago

virtualizing the data retrieval ? Did you mean visualizing?

However, 2000 records should be fairly quick. Are you sure you have an @Column( index = true ) on your Data_Id field?

ktomek commented 10 years ago

Use SimpleCursorAdapter, CursorLoader and LoaderManager to avoid loading all objects to memory.

https://github.com/pardom/ActiveAndroid/wiki/Using-the-content-provider