Advertisement
Guest User

Untitled

a guest
May 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package com.example.regytadhea.storageapps;
  2.  
  3. import android.content.SharedPreferences;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.EditText;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11. EditText inputText;
  12. EditText outputText;
  13.  
  14. static String PREF_NAME = "DB_DATA";
  15.  
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_main);
  20.  
  21. inputText = findViewById(R.id.inputText);
  22. outputText = findViewById(R.id.outputText);
  23.  
  24. }
  25.  
  26. public void clickSave(View view) {
  27. SharedPreferences preferences =
  28. getSharedPreferences(PREF_NAME,0);
  29.  
  30. SharedPreferences.Editor editor = preferences.edit();
  31.  
  32. editor.putString("mytext",
  33. inputText.getText().toString());
  34. editor.commit();
  35. }
  36.  
  37. public void clickLoad(View view) {
  38. SharedPreferences preferences =
  39. getSharedPreferences(PREF_NAME,0);
  40.  
  41. String mytext = preferences.getString("mytext", "");
  42. outputText.setText(mytext);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement