Event onResume does not run in preferencescreen



I have a preferencescreen containing 20 preferencescreen, I need to update the values of "summary" when I edited a edittextpreference. To update the value I have to close and reopen the screen preferably need to be updated when I get to the screen without having to close it.


Sorry for my bad English


.xml



<PreferenceScreen
android:key="s1"
android:title="Proyecto 1" >

<EditTextPreference
android:key="1"
android:title="Proyecto 1"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p11"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p12"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p13"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p14"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p15"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>

<PreferenceScreen
android:key="s2"
android:title="Proyecto 2" >

<EditTextPreference
android:key="2"
android:title="Proyecto 2"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p21"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p22"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p23"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p24"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p25"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>

<PreferenceScreen
android:key="s3"
android:title="Proyecto 3" >

<EditTextPreference
android:key="3"
android:title="Proyecto 3"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p31"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p32"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p33"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p34"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p35"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s4"
android:title="Proyecto 4" >

<EditTextPreference
android:key="4"
android:title="Proyecto 4"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p41"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p42"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p43"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p44"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p45"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s5"
android:title="Proyecto 5" >

<EditTextPreference
android:key="5"
android:title="Proyecto 5"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p51"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p52"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p53"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p54"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p55"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s6"
android:title="Proyecto6" >

<EditTextPreference
android:key="6"
android:title="Proyecto 6"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p61"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p62"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p63"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p64"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p65"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s7"
android:title="Proyecto 7" >

<EditTextPreference
android:key="7"
android:title="Proyecto 7"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p71"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p72"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p73"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p74"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p75"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s8"
android:title="Proyecto 8" >

<EditTextPreference
android:key="8"
android:title="Proyecto 8"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p81"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p82"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p83"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p84"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p85"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s9"
android:title="Proyecto 9" >

<EditTextPreference
android:key="9"
android:title="Proyecto 9"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p91"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p92"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p93"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p94"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p95"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s10"
android:title="Proyecto 10" >

<EditTextPreference
android:key="10"
android:title="Proyecto 10"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p101"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p102"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p103"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p104"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p105"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s11"
android:title="Proyecto 11" >

<EditTextPreference
android:key="11"
android:title="Proyecto 11"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p111"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p112"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p113"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p114"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p115"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s12"
android:title="Proyecto 12" >

<EditTextPreference
android:key="12"
android:title="Proyecto 12"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p121"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p122"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p123"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p124"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p125"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s13"
android:title="Proyecto 13" >

<EditTextPreference
android:key="13"
android:title="Proyecto 13"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p131"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p132"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p133"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p134"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p135"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s14"
android:title="Proyecto 14" >

<EditTextPreference
android:key="14"
android:title="Proyecto 14"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p141"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p142"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p143"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p144"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p145"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s15"
android:title="Proyecto 15" >

<EditTextPreference
android:key="15"
android:title="Proyecto 15"
android:summary="@string/nomproy" />

<EditTextPreference
android:key="p151"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p152"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p153"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p154"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p155"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s16"
android:title="Proyecto 16" >

<EditTextPreference
android:key="16"
android:title="Proyecto 16"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p161"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p162"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p163"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p164"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p165"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s17"
android:title="Proyecto 17" >

<EditTextPreference
android:key="17"
android:title="Proyecto 17"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p171"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p172"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p173"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p174"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p175"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s18"
android:title="Proyecto 18" >

<EditTextPreference
android:key="18"
android:title="Proyecto 18"
android:summary="@string/nomproy" />

<EditTextPreference
android:key="p181"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p182"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p183"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p184"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p185"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s19"
android:title="Proyecto 19" >

<EditTextPreference
android:key="19"
android:title="Proyecto 19"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p191"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p192"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p193"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p194"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p195"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>
<PreferenceScreen
android:key="s20"
android:title="Proyecto20" >

<EditTextPreference
android:key="20"
android:title="Proyecto 20"
android:summary="@string/nomproy"/>

<EditTextPreference
android:key="p201"
android:summary="@string/resppos"
android:title="@string/pregunta1" />
<EditTextPreference
android:key="p202"
android:summary="@string/resppos"
android:title="@string/pregunta2" />
<EditTextPreference
android:key="p203"
android:summary="@string/resppos"
android:title="@string/pregunta3" />
<EditTextPreference
android:key="p204"
android:summary="@string/resppos2"
android:title="@string/pregunta4" />
<EditTextPreference
android:key="p205"
android:summary="@string/resppos2"
android:title="@string/pregunta5" />
</PreferenceScreen>

</PreferenceScreen>


.java



public class CheckList extends PreferenceActivity implements
OnSharedPreferenceChangeListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.checklist);

// modificarSummary();
}

private void modificarSummary() {

SharedPreferences sp = getPreferenceScreen().getSharedPreferences();

PreferenceScreen ps1 = (PreferenceScreen) findPreference("s1");
ps1.setSummary(sp.getString("1", ""));

PreferenceScreen ps2 = (PreferenceScreen) findPreference("s2");
ps2.setSummary(sp.getString("2", ""));

PreferenceScreen ps3 = (PreferenceScreen) findPreference("s3");
ps3.setSummary(sp.getString("3", ""));

PreferenceScreen ps4 = (PreferenceScreen) findPreference("s4");
ps4.setSummary(sp.getString("4", ""));

PreferenceScreen ps5 = (PreferenceScreen) findPreference("s5");
ps5.setSummary(sp.getString("5", ""));

PreferenceScreen ps6 = (PreferenceScreen) findPreference("s6");
ps6.setSummary(sp.getString("6", ""));

PreferenceScreen ps7 = (PreferenceScreen) findPreference("s7");
ps7.setSummary(sp.getString("7", ""));

PreferenceScreen ps8 = (PreferenceScreen) findPreference("s8");
ps8.setSummary(sp.getString("8", ""));

PreferenceScreen ps9 = (PreferenceScreen) findPreference("s9");
ps9.setSummary(sp.getString("9", ""));

PreferenceScreen ps10 = (PreferenceScreen) findPreference("s10");
ps10.setSummary(sp.getString("10", ""));

PreferenceScreen ps11 = (PreferenceScreen) findPreference("s11");
ps11.setSummary(sp.getString("11", ""));

PreferenceScreen ps12 = (PreferenceScreen) findPreference("s12");
ps12.setSummary(sp.getString("12", ""));

PreferenceScreen ps13 = (PreferenceScreen) findPreference("s13");
ps13.setSummary(sp.getString("13", ""));

PreferenceScreen ps14 = (PreferenceScreen) findPreference("s14");
ps14.setSummary(sp.getString("14", ""));

PreferenceScreen ps15 = (PreferenceScreen) findPreference("s15");
ps15.setSummary(sp.getString("15", ""));

PreferenceScreen ps16 = (PreferenceScreen) findPreference("s16");
ps16.setSummary(sp.getString("16", ""));

PreferenceScreen ps17 = (PreferenceScreen) findPreference("s17");
ps17.setSummary(sp.getString("17", ""));

PreferenceScreen ps18 = (PreferenceScreen) findPreference("s18");
ps18.setSummary(sp.getString("18", ""));

PreferenceScreen ps19 = (PreferenceScreen) findPreference("s19");
ps19.setSummary(sp.getString("19", ""));

PreferenceScreen ps20 = (PreferenceScreen) findPreference("s20");
ps20.setSummary(sp.getString("20", ""));



}

@Override
protected void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
modificarSummary();
}

@Override
protected void onStop() {
super.onStop();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}


@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {

Preference pref = findPreference(key);
if (pref instanceof PreferenceScreen) {
EditTextPreference etp = (EditTextPreference) pref;
pref.setSummary(etp.getText());
modificarSummary();
}

}
}

No comments:

Post a Comment