android - EditTextPreference crashes on OK press -


i have preferencefragment activity shows following edittextpreference:

<edittextpreference             android:key="year"             android:title="@string/prefs_yearpicker"             android:summary="@string/prefs_yearpickersummary"             android:textallcaps="true"/> 

but when want change value, shows no cursor, , when press ok, crashes, returning following message:

11-27 07:59:33.900: e/androidruntime(23355): fatal exception: main 11-27 07:59:33.900: e/androidruntime(23355): java.lang.indexoutofboundsexception: replace (0 ... -1) has end before start 11-27 07:59:33.900: e/androidruntime(23355):    @ android.text.spannablestringbuilder.checkrange(spannablestringbuilder.java:1009) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.text.spannablestringbuilder.replace(spannablestringbuilder.java:441) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.text.spannablestringbuilder.delete(spannablestringbuilder.java:212) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.text.spannablestringbuilder.delete(spannablestringbuilder.java:30) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.view.inputmethod.baseinputconnection.deletesurroundingtext(baseinputconnection.java:242) 11-27 07:59:33.900: e/androidruntime(23355):    @ com.android.internal.view.iinputconnectionwrapper.executemessage(iinputconnectionwrapper.java:382) 11-27 07:59:33.900: e/androidruntime(23355):    @ com.android.internal.view.iinputconnectionwrapper$myhandler.handlemessage(iinputconnectionwrapper.java:77) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.os.handler.dispatchmessage(handler.java:99) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.os.looper.loop(looper.java:137) 11-27 07:59:33.900: e/androidruntime(23355):    @ android.app.activitythread.main(activitythread.java:5227) 11-27 07:59:33.900: e/androidruntime(23355):    @ java.lang.reflect.method.invokenative(native method) 11-27 07:59:33.900: e/androidruntime(23355):    @ java.lang.reflect.method.invoke(method.java:511) 11-27 07:59:33.900: e/androidruntime(23355):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:795) 11-27 07:59:33.900: e/androidruntime(23355):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:562) 11-27 07:59:33.900: e/androidruntime(23355):    @ dalvik.system.nativestart.main(native method) 

preferences class code:

public class preferences extends actionbaractivity  {      final context context = getbasecontext();      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         // set layout         setcontentview(r.layout.preferences_layout);          // display fragment main content.         getfragmentmanager().begintransaction()                 .replace(r.id.preferences, new settingsfragment())                 .commit();          toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);         if (toolbar != null) {             setsupportactionbar(toolbar);         }          if (build.version.sdk_int >= build.version_codes.honeycomb) {             getsupportactionbar().setdisplayhomeasupenabled(true);         }     } }  public static class settingsfragment extends preferencefragment implements onsharedpreferencechangelistener {         @override         public void oncreate(bundle parambundle) {                  super.oncreate(parambundle);                 addpreferencesfromresource(r.xml.preferences);                  // shared preferences                 sharedpreferences prefs = getpreferencescreen().getsharedpreferences();                 // set on change listener                 prefs.registeronsharedpreferencechangelistener(this);                 // update summaries                 updateall(prefs);              } } 

i've tried without on change listener, same result.

void updateall(sharedpreferences prefs) {      // set summary     edittextpreference edittextpref = (edittextpreference) findpreference("year");     edittextpref.setsummary(prefs.getstring("year", ""));      // set summary of interval     listpreference listpref = (listpreference) findpreference("notificationsinterval");     string intervalvalue = prefs.getstring("notificationsinterval", "1800000");     string text = mstoh(integer.valueof(intervalvalue));     listpref.setsummary(text);  } 

what doing wrong? in advance!

final solution: see own answer.

just move updateall method onsharedpreferenceschanged().

@override public void onsharedpreferencechanged (sharedpreferences sharedpreferences, string key) {         updateall (sharedpreferences);  } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -