Display SQLite result in Listview in Android

In my android app, I have a combo box activity that displays about 4000 items that are stored locally in a SQLite database. If I do an item edit, how can I only get that change in the list, without having to update the list of all items (which means a new query for 4000 results)? This query slows down performance.

I would like something like NSFetchedResultsController ios.

+3


source to share


3 answers


The strategy should be -



  • When you edit a contact, if the update is successful, you just get the most recent information from the db for that particular contact only.
  • Update the edited contact object at the original position of the list / array source.
  • Call adapter.notifyDataSetChanged()

    .
+2


source


  • you must have an ID for each contact in the SQL Lite database.
  • when you edit a contact update that contains a specific record in the database based on the id.
  • If the update is successful, then the information sent to the database is successfully saved.
  • now you can use the same information to update your ArrayList / HashMap, whatever you use to populate your list. Example: Suppose you edited the 3rd index contact in your list on a successful update you add, for example yourarraylist.add (3, contact);

  • and fire notifydatasetChanged.



+1


source


Try the following:

  • Try fetching data from db, but do it on a different thread that won't affect the main UIThread.
  • Then you can call adapter.notifyDataSetChanged () on the adapter object. It will do the job, I hope :).
+1


source







All Articles