Actually I have a listview in one activity and edittext in another activity. When I enter data in edittext and click the button, data should add to listview. So I am able to do that. But when I again do the same with the edittext, the value should append to the value first entered. It should be the same for every value entered in the edittext. how to restore values when we navigate to one activity and come back to same activity.
Asked
Active
Viewed 130 times
3 Answers
0
Declare the variable as static, this variables allows keep the same variable alive between activities.

Diego Fernando Lara
- 94
- 6
-
All the variables, you are saying ?? or Just the one – user3798872 Jun 01 '15 at 17:13
-
Oh i´m sorry i read wrong, look, what you do this is use the function .notifyDataSetChanged(); to update the adapter and show the new element. Put your code for more information. – Diego Fernando Lara Jun 01 '15 at 17:19
0
It seems you are passing the value of EditText from one Activity to another using Explicit Intent. In your case you can solve your problem by putting following code inside onCreate method as:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
listView.add(string_you received_from_previous_Activity);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
for more information you can follow this links
2.Link 2
hope this helps you ...

Community
- 1
- 1

Santosh Bhandary
- 359
- 2
- 3
- 19
0
Use shared preference. It is the best option you got. You can create different variable according to the requirement and values will not change unless you update them.
Or local database.
Passing value through intent wont help you.

pratz9999
- 539
- 4
- 20
-
Thanks for that!! I am able to restore the value when i again login to my app using sharedpreferences. But let me know how to append values to my listview presented in another activity. – user3798872 Jun 02 '15 at 21:00
-
You should store these values in local database to extend the listview every time you update the edittext. This is the best way. If not the you have to create multiple variables and store the value using shared preference. – pratz9999 Jun 03 '15 at 11:00
-
Okay got it!! And When I again run the application I am able to see the last entered value in the listview. What I have to do to get all the values which are entered before. – user3798872 Jun 05 '15 at 01:18
-
-
-
Thank u!! Is there any other way to retrieve other than that. Because I am not completely aware of that. – user3798872 Jun 10 '15 at 00:35
-
depends.. sqlite is best and easy.. trust me.. try it and if you need help just post it @user3798872 – pratz9999 Jun 10 '15 at 03:38