Search code examples
performanceandroid-listviewandroid-cursoradapter

performing update queries for a drag drop listview


I am using a drag and drop listview backed by cursor adapter. To maintain the database I am updating the positions of database entries at the time of dragging a view.For this I am using the conventional method of SQLiteDatabase.rawQuery and then when the update operations are done I call notifyDataSetChanged to call my bindview method of cursoradapter to reposition the entries. This however is lagging the UI and leaving the app unresponsive. I tried to move all my database operations to AsyncTask using a single instance of my database. This also is lagging my UI as the threads are queuing and the listview has to wait till each asynctask completes.

My ListView is always waiting for the queries to complete.

What should be the correct way of execution for this scenario? Will the use of CursorLoader give me a snappy UI?

I've seen many apps doing drag and drop efficiently and most of them are using array adapters. But I need to update my database as the enteries in listview are moved.

Please tell me an efficient way...

EDIT: Ok I am re-implementing the structure as I just found out that the Async Tasks are not even queuing up.They are made for concurrency.

The right question to ask should be how to queue database queries in FIFO order? Any pointers regarding that?

Regards, Parvaz Bhaskar


Solution

  • I finally managed my FIFO calls to database by implementing Threads and only using one handler to post my queries. This queued up my database queries and I updated my UI beforehand... So I don't have to wait for my queries to Finish.

    Thanks SO for all the links that I found were eventually SO links.