Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. package com.example.ted.android_sharedprefs;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.TextView;
  10.  
  11. public class ActivityTwo extends AppCompatActivity {
  12.  
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_activity_two);
  17.  
  18. Button btnLoad = (Button) findViewById(R.id.btnLoad);
  19. final TextView tvUsername = (TextView) findViewById(R.id.tvUsername);
  20. final TextView tvPassword = (TextView) findViewById(R.id.tvPassword);
  21.  
  22. assert btnLoad != null;
  23. btnLoad.setOnClickListener(new View.OnClickListener() {
  24. @Override
  25. public void onClick(View v) {
  26. SharedPreferences sp = getSharedPreferences("MyData", Context.MODE_PRIVATE);
  27. String musername = sp.getString("username", "no data retrieved");
  28. String mpassword = sp.getString("password", "no data retrieved");
  29. tvUsername.setText(musername);
  30. tvPassword.setText(mpassword);
  31. }
  32. });
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement