In haste I made this version of a dynamically configured screen with settings

onCreate(....{ EditTextPreference[] etprefArr = new EditTextPreference[10]; for (int i = 0; i < etprefArr.length; i++) { etprefArr[i] = new EditTextPreference(this); etprefArr[i].setKey("etpOwner" + i); etprefArr[i].setTitle(preference.getString("etpOwner" + i, null)); etprefArr[i].setIcon(R.drawable.telephone_1_32); ownerScreen.addPreference(etprefArr[i]); if (etprefArr[i].getTitle()==null ||etprefArr[i].getTitle().equals("")){ break; } } 

The creation of an EditTextPreference works as it was intended (if the existing EditTextPreference filled, a new one appears, only the question is that the PreferenceScreen containing the EditTextPreference data is updated only after the re-creation of PreferenceActivity .

Tell me how to dynamically form the PreferenceScreen . There was an idea to create your own class that extends the PreferenceScreen or EditTextPreference . Perhaps there are more correct / simple solutions.

enter image description here

The current screen version looks like this: The "static" EditTextPreference "Add" has been added to it. When I click on it, a standard dialog appears, I enter a new value and, when I save it, I save the value to a new one in the Preference under my name + (count + 1). As a result, the new value is added but not displayed on the PreferenceScreen .
And so for each time you click "Add."
The next time you PreferenceScreen this PreferenceScreen they PreferenceScreen through all the Preferences with the name "+ (count + 1,2,3 ...)". I get a screen with values, but when they are corrected, old values ​​are displayed on the screen

    1 answer 1

    Here they say that it is necessary so:

     setPreferenceScreen(null); addPreferencesFromResource(R.xml.preferences); 
    • Thanks for the link, until I figured out how to apply this option. If my PreferenceActivity is dynamically generated and addPreferencesFromResource(R.xml.pref); not used until I tried the .setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { return true; } }); option .setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { return true; } }); it works, but for each component to add, a lot of code is obtained. probably not very correct. - x555xx
    • Good day! I could not figure out how to update the PreferenceScreen, if all my settings are configured dynamically and resources are not used. - x555xx
    • @ x555xx, something I do not immediately understand what exactly is not working for you and how it should be, but try hanging up the listeners to change the settings and do something in their callback. - Yuriy SPb
    • redesigned the text in the topic a little, I think it became clearer - x555xx 2:41 pm