How to keep dynamic layout (custom) in Android?

I have a button on my home screen that will add an edit text box every time it is clicked (I limited it to 20 for best practice). It is basically a small budgeting application. I want the user to fill in X amount of dollars in one of the fields. Then when they are ready, go back to the application one more time and that the created EditText is still filled with value there. I know how to use SharedPerfrences to store the value. However, I don't know how to save this newly created EditText when the user comes back.

I am actively expanding and have a button and datepick associated with each EditText, so soon click on the button to create three objects instead of one. But I want to get a job first, and later apply this principle to others. Any suggestions?

+3


source to share


2 answers


Sounds like a good candidate for a SQLite database.

For example, I am using a SQLite database to store and call the codes and widget types that the user has ordered in my application.



Note that you will never want to try to store and call the actual object EditText

View

. In your database, you need to design your own table format that matches the information you need to store. If you just need to store the states of a series of fields EditText

, then it can be as simple as having a table with one column that contains a string value for each row. To re-create your UI from this database, you must loop and create a new instance EditText

and set the text of each from the table.

+1


source


You will need to use the android interface Parcelable

, refer to this for how to implement it, see this question I asked on StackOverflow, it has a good answer.



0


source







All Articles