I am working on this app where I have one EditText field where you can write something and then it get saved and added to a list(TextView). I save the content of the EditText in this way:
saved += "*" + editTextFelt.getText().toString() + ". \n";
saved is a String.
Everything works fine, I can even reload the app and it’s still displayed in the TextView, but if I try to write something and save it everything that was there, now disappears. Why?
CODE:
init Method()
sp = getSharedPreferences(fileName, 0);
betaView = (TextView)findViewById(R.id.betaTextView);
I’ve got a button to send the text, and this is like:
public void onClick(View v) {
switch(v.getId()){
case R.id.btnSend:
saved += "*" + editTextFelt.getText().toString() + ". \n";
SharedPreferences.Editor editor = sp.edit();
editor.putString("SAVED", saved);
editor.commit();
betaView.setText(sp.getString("SAVED", "Empty"));
How are you saving it? because when you save a text against a variable it replaces the previous one.
So you need to get the previous one and then append the new one and then again save it to
SharedPreferences, something like this:now set this appended text to your
TextViewlike this: