Skip to content
Advertisement

How to save data from RecyclerView EditText

I have RecyclerView with multiple EditText. I want to save data that user provided to the EditText, store it and retrieve it after opening an app again.

I have an app where user tracks how many repetitions of certain exercise they did and obviously I want it to be saved somehow and to be retrieved later, but I don’t know how to do this with RecyclerView. Usually I would just send certain EditText data to the database and then I would retrieve it, but in RecyclerView I don’t know how to access that data as it is created dynamically(?) Sorry if I am wrong with something, but I am very new in Android programming.

Below is my code.

JavaScript

Adapter code:

JavaScript

Advertisement

Answer

It is not so hard to save data with SharedPreferences. But, it does take a few lines of code. So, I’d prefer you to use my library. It is even faster to use. You can add it to your app using the README.md file. Now, I can give you the entire adapter code with that functionality below:

JavaScript

That does the init part for the db. But, because I don’t find your edit text anywhere in the adapter, I have not added that part. But, the code for that edit text will be like this:

JavaScript

But, dont forget to change the key in that place according your requirements.

Advertisement