Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nitish Bhayana
1,467 PointsAllowing a user to change their password using EditTextPreference?
I've got a settings fragment which allows the user to change a bunch of information (such as their password), and I'm using a PreferenceScreen in a separate xml file titled preferences.xml. When I launch the Fragment and go to the Preferences, it allows me to enter values (such as a new password) in the default alert dialog that pops up for EditTextPreference and the data also saves correctly. I checked this using the File Explorer in DDMS to confirm this.
The trouble I'm having is actually getting a reference to that specific EditTextPreference and actually saving the new password.
The EditTextPreference for password looks like
<EditTextPreference
android:key="change_password_key"
android:title="Change Password"
android:inputType="textPassword"
android:persistent="true"/>
I don't know how to reference this attribute in my SettingsFragment however.
my SettingsActivity:
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
public void onClick(DialogInterface dialogInterface, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.setPassword("change_password_key");
currentUser.saveInBackground();
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
}
}
}