In my app once user provide three inputs, AsyncTask
starts which connects to the server and gets info for two more fields. Once AsyncTask
is finished, I want to set those two received values in opened setting page.
I searched and try this code, but not updating summary for fields for which value has fetched from server.
Problem is I'm not able to set values received from server as summary to EditTextPreference
. If I reopen settngs page it shows value not without reopening.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updatePreference(key);
}
private void updatePreference(String key) {
if (key.equals("id")) {
Preference preference = findPreference(key);
if (preference instanceof EditTextPreference) {
EditTextPreference editTextPreference = (EditTextPreference) preference;
if (editTextPreference.getText().trim().length() > 0) {
editTextPreference.setSummary(editTextPreference.getText());
} else {
editTextPreference.setSummary("");
}
}
} else if (key.equals("sclass")) {
Preference preference = findPreference(key);
if (preference instanceof EditTextPreference) {
EditTextPreference editTextPreference = (EditTextPreference) preference;
if (editTextPreference.getText().trim().length() > 0) {
editTextPreference.setSummary(editTextPreference.getText());
} else {
editTextPreference.setSummary("");
}
}
}
}