I'm new to Android and can't quite figure out the right approach for the problem I'm trying to solve. I have an ExpandableListView
with several items. Each item has an EditText
, except the last item has a button. The contents of the EditText
s are to be loaded from the database. When the button is clicked or when the activity is navigated away from, I want to save the contents of each EditText
to my database.
I'm not sure what to call from the activity's class, what to call from my adapter, and how exactly to access each item appropriately. Code is welcome but not necessary, I'm just looking for guidance on the general approach. Thanks.
I'd recommend putting a method in your adapter called saveAllValues. It iterates through the list of objects in the adapter and saves them to the database. Call this when your button is clicked and in your activity's onStop() method (which is called when the activity is no longer visible).
You should have your activity fetch the values for the item IDs in an AsyncTask in its onCreate method. Then pass the list of id/value pairs to the adapter in its constructor. It should maintain this list so it can go back through it and save the IDs and values to the DB.