Search Results

Search found 1 results on 1 pages for 'user1742524'.

Page 1/1 | 1 

  • retrieving and restoring textview information from sharedpreferences

    - by user1742524
    I have an activity that allows user to enter notes and store them in dynamically created textviews. However, when the use leaves the activity and returns, all the created textviews disappear. How can i store store or retrieve all of these created textviews, whenever i return to the activity? Also, i think that my sharedpreferences will be overwriting each time a new textview is added. Any suggestions? public class DocNoteActivity extends Activity { private LinearLayout nLayout; private EditText etDocNote; private Button btnAdd1; public static final String PREFS_NAME = "MyPrefsFile"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.adddocnote); etDocNote = (EditText) findViewById(R.id.editDocNote); btnAdd1 = (Button) findViewById(R.id.btnAdd1); nLayout = (LinearLayout) findViewById(R.id.linearLayout); TextView tvNote = new TextView(this); tvNote.setText(""); btnAdd1.setOnClickListener(onClick()); } private OnClickListener onClick() { // TODO Auto-generated method stub return new OnClickListener(){ public void onClick(View v) { // TODO Auto-generated method stub String newDocNote = etDocNote.getText().toString(); nLayout.addView(createNewTextView(newDocNote)); getSharedPreferences("myprefs", 0).edit().putString("etDocNote", newDocNote).commit(); } }; } private TextView createNewTextView(String newText) { // TODO Auto-generated method stub LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); TextView tvNote = new TextView(this); tvNote.setLayoutParams(lparams); tvNote.setText(newText); return tvNote; } }

    Read the article

1