Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditTexts AutoSave

Tags:

android

I have a database object which includes a lot of String fields. Right now, these string fields are managed by the user through an activity with a lot of edit texts. However, I'm having trouble saving all of the information from my EditTexts to a database. I've tried doing this when the activity calls onPause but it is not working how I would like (I'm using a ListView with the EditTexts so it's hard to say if the views will be there). I've been looking at the text watcher but it seems really tedious to add one for every EditText, some of which are created dynamically.

I've considered extending EditText and implementing something to use the TextWatcher but I'm again not sure about the best way to go about this.

Anybody have any suggestions on how I can accomplish this? Thanks for the help.

like image 831
kevin.w.johnson Avatar asked Mar 24 '26 04:03

kevin.w.johnson


1 Answers

I would say you should hold a reference to each of these EditText objects in an ArrayList and then use an array list adapter to provide the data to your listview.

when any of the EditText's are changed you can call notifyDatasetChanged on the adapter. in the onPause method you can loop thru the ArrayList and save each to your database.

like image 117
nPn Avatar answered Mar 28 '26 02:03

nPn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!