Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. package com.fps.iHealthFirst;
  2.  
  3. import android.app.Activity;
  4. import android.content.SharedPreferences;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.RadioButton;
  11. import android.widget.RadioGroup;
  12. import android.widget.Spinner;
  13. import android.widget.Toast;
  14.  
  15. public class Profile_Pref extends Activity {
  16.  
  17. // Game preference values
  18. public static final String USER_PREFERENCES = "User Profile";
  19. public static final String FNAME = "FNAME";
  20. public static final String LNAME = "LNAME";
  21. public static final String MNAME = "MNAME";
  22. public static final String AGE = "AGE";
  23. public static final String DOB = "DOB";
  24. public static final String WEIGHT_LBS = "WEIGHT(LBS)";
  25. public static final String HEIGHT_FT = "HEIGHT(FT)";
  26. public static final String HEIGHT_IN = "HEIGHT(IN)";
  27. public static final String BODYTYPE = "BODY TYPE";
  28. public static final String BLOODTYPE = "BLOOD TYPE";
  29. public static final String GENDER = "GENDER";
  30.  
  31. private SharedPreferences myPrefs;
  32. private boolean loggedIn;
  33.  
  34. EditText fname, lname, mname, dob, age, weight_lbs, height_ft, height_in;
  35. Spinner bloodtype, bodytype;
  36. RadioGroup gender;
  37. RadioButton male, female;
  38. Button btSave, btCancel;
  39.  
  40.  
  41. protected void onCreate(Bundle savedInstanceState)
  42. {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.iprofile);
  45.  
  46.  
  47. myPrefs = getSharedPreferences(USER_PREFERENCES, MODE_PRIVATE);
  48.  
  49. loggedIn = myPrefs.getBoolean("loggedIn", false); //default to false if the value has not been set
  50.  
  51.  
  52. if(loggedIn)
  53. {
  54. //do stuff
  55.  
  56.  
  57.  
  58. }
  59. else
  60. {
  61. //do other stuff
  62. }
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. public void onClick(View v) {
  73. // TODO Auto-generated method stub
  74.  
  75. switch(v.getId()){
  76.  
  77. case R.id.btProfileSave:
  78. //get entered value and set to a variable
  79. String fnameText = fname.getText().toString();
  80. String lnameText = lname.getText().toString();
  81. String mnameText = mname.getText().toString();
  82. String dobText = dob.getText().toString();
  83. String weight_lbs_Text = weight_lbs.getText().toString();
  84. String height_ft_Text = height_ft.getText().toString();
  85. String height_in_Text = height_in.getText().toString();
  86. String bodytypeText = bodytype.getContext().toString();
  87. String bloodtypeText = bloodtype.getContext().toString();
  88. String genderText = gender.getContext().toString();
  89. String ageText = age.getText().toString();
  90.  
  91. //empty edit text field
  92. //name_edit_text.setText("");
  93. //empty edit text field
  94. //name_edit_text.setText("");
  95.  
  96. //SAVE shared pref value
  97. SharedPreferences.Editor editor = myPrefs.edit();
  98. editor.putString("fname", fnameText);
  99. editor.putString("lname", lnameText);
  100. editor.putString("mname", mnameText);
  101. editor.putString("dob", dobText);
  102. editor.putString("weight_lbs", weight_lbs_Text);
  103. editor.putString("height_ft", height_ft_Text);
  104. editor.putString("height_in", height_in_Text);
  105. editor.putString("bodytype", bodytypeText);
  106. editor.putString("bloodtype", bloodtypeText);
  107. editor.putString("gender", genderText);
  108. editor.putString("age", ageText);
  109. editor.commit();
  110.  
  111. //show button after saving
  112. Toast.makeText(Profile_Pref.this,
  113. "You entered: " + fnameText,
  114. Toast.LENGTH_SHORT)
  115. .show();
  116.  
  117. break;
  118. case R.id.btProfileCancel:
  119. //RETRIEVE/load the saved shared pref value
  120. String name = myPrefs.getString("name", null);
  121. Toast.makeText(Profile_Pref.this,
  122. "Saved Name is: " + name,
  123. Toast.LENGTH_LONG)
  124. .show();
  125. break;
  126.  
  127. }
  128. }
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement