Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.regytadhea.storageapps;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity {
- EditText inputText;
- EditText outputText;
- static String PREF_NAME = "DB_DATA";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- inputText = findViewById(R.id.inputText);
- outputText = findViewById(R.id.outputText);
- }
- public void clickSave(View view) {
- SharedPreferences preferences =
- getSharedPreferences(PREF_NAME,0);
- SharedPreferences.Editor editor = preferences.edit();
- editor.putString("mytext",
- inputText.getText().toString());
- editor.commit();
- }
- public void clickLoad(View view) {
- SharedPreferences preferences =
- getSharedPreferences(PREF_NAME,0);
- String mytext = preferences.getString("mytext", "");
- outputText.setText(mytext);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement