How to add data dynamic on recyclerView and save the data?

后端 未结 2 1177
执念已碎
执念已碎 2020-12-22 06:21

I want to save the data when user input edit text.

It can show on recyclerView and the app can show it again when the app had restarted.

I try to user share

2条回答
  •  感情败类
    2020-12-22 06:49

    Try moving myAdapter.notifyDataSetChanged(); to the end of onResume(). You don't need it inonCreate() since you just created that adapter and the data did not change after.

    Also, you don't need to call this part in both onCreate() and onResume(). Remove it from onCreate(). You are just adding the same item twice to your list that way:

    String getUserInputBlood = preferences.getString("uerInputBlood", "");  
     listData.add(getUserInputBlood);
    

    SharedPreferences are usually used to store a few key/value data items needed by your application. They are not intended for storing lists.

    If you are trying to store all the list values, you should use some other form of data storage, e.g. a SQLite database. For more details, see storage options

提交回复
热议问题