Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. Button add_btn;
  4. TextView title_txt , priority_txt , id_txt;
  5. SharedPreferences preferences;
  6.  
  7.  
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13.  
  14.  
  15.  
  16. add_btn = findViewById(R.id.add_btn);
  17. title_txt = findViewById(R.id.title_txt);
  18. priority_txt = findViewById(R.id.priority_txt);
  19. id_txt = findViewById(R.id.id_txt);
  20.  
  21.  
  22.  
  23. add_btn.setOnClickListener(new View.OnClickListener() {
  24. @Override
  25. public void onClick(View v) {
  26. Intent intent = new Intent(MainActivity.this , AddTodoActivity.class);
  27. startActivity(intent);
  28. }
  29. });
  30. }
  31.  
  32. @Override
  33. protected void onStart() {
  34. super.onStart();
  35. preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  36.  
  37. retreiveData();
  38. }
  39.  
  40. private void retreiveData() {
  41.  
  42. String title = preferences.getString("title" , "none");
  43. int id = preferences.getInt("id" , 0);
  44. boolean priority = preferences.getBoolean("priority" , false);
  45.  
  46. title_txt.setText("Title : " + title);
  47. id_txt.setText("Id : " + id);
  48. if(priority){
  49. priority_txt.setText("Priority : High" );
  50. }else {
  51. priority_txt.setText("Priority : Low");
  52. }
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement