Skip to content

Instantly share code, notes, and snippets.

@finleyChen
Created April 1, 2013 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finleyChen/5288820 to your computer and use it in GitHub Desktop.
Save finleyChen/5288820 to your computer and use it in GitHub Desktop.
load the user data from shared preferences. If there is no data make sure that we set it to something reasonable.
private void loadUserData() {
// We can also use log.d to print to the LogCat
Log.d(TAG, "loadUserData()");
// Load and update all profile views
// Get the shared preferences - create or retrieve the activity
// preference object
String mKey = getString(R.string.preference_name);
SharedPreferences mPrefs = getSharedPreferences(mKey, MODE_PRIVATE);
// Load the user name
mKey = getString(R.string.preference_key_profile_name);
String mValue = mPrefs.getString(mKey, " ");
// Load the user email
mKey = getString(R.string.preference_key_profile_email);
mValue = mPrefs.getString(mKey, " ");
((EditText) findViewById(R.id.editEmail)).setText(mValue);
// Load the user phone
mKey = getString(R.string.preference_key_profile_phone);
mValue = mPrefs.getString(mKey, " ");
((EditText) findViewById(R.id.editPhone)).setText(mValue);
// Please Load gender info and set radio box
mKey = getString(R.string.preference_key_profile_gender);
int mIntValue = mPrefs.getInt(mKey, -1);
// In case there isn't one saved before:
if (mIntValue >= 0) {
// Find the radio button that should be checked.
RadioButton radioBtn = (RadioButton) ((RadioGroup) findViewById(R.id.radioGender))
.getChildAt(mIntValue);
// Check the button.
radioBtn.setChecked(true);
Toast.makeText(getApplicationContext(),
"number of the radioButton is : " + mIntValue,
Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment