Created
April 1, 2013 23:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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