android - change color in strings.xml and onClick method -
hi strings.xml.
<item><font color ="red">mnasekundę</font></item> i changed color of item red, unfortunately logcat that: java.lang.illegalstateexception: not execute method android:onclick , oncick method:
public void konwertuj(view view) { if (fromedittext.gettext().tostring().length() < 1) { toast.maketext(glownapredkosc.this, "musisz wpisać dowolną liczbę", toast.length_long).show(); } else { // string spinners , number edittext string fromstring = (string) fromspinner.getselecteditem(); string tostring = (string) tospinner.getselecteditem(); double input = double.valueof(fromedittext.gettext().tostring()); // convert strings in our unit enu, konwerterpredkosc.jednostka fromjednostka = konwerterpredkosc.jednostka.fromstring(fromstring); konwerterpredkosc.jednostka tojednostka = konwerterpredkosc.jednostka.fromstring(tostring); // create converter object , convert! konwerterpredkosc konwerter = new konwerterpredkosc(fromjednostka, tojednostka); double result = konwerter.convert(input); toedittext.settext(string.valueof(result)); } p.s when font color black, works great.
thanks reading
complete output:
java.lang.illegalstateexception: not execute method android:onclick @ android.view.view$declaredonclicklistener.onclick(view.java:4452) @ android.view.view.performclick(view.java:5198) @ android.view.view$performclick.run(view.java:21147) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.method.invoke(native method) @ android.view.view$declaredonclicklistener.onclick(view.java:4447) @ android.view.view.performclick(view.java:5198) @ android.view.view$performclick.run(view.java:21147) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616) caused by: java.lang.classcastexception: android.text.spannedstring cannot cast java.lang.string @ com.example.barto.konwerter2.glownapredkosc.konwertuj(glownapredkosc.java:73) @ java.lang.reflect.method.invoke(native method) @ android.view.view$declaredonclicklistener.onclick(view.java:4447) @ android.view.view.performclick(view.java:5198) @ android.view.view$performclick.run(view.java:21147) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method)
try this: toedittext.settextcolor(this.getresources().getcolor(r.color.red)); without changing in .xml.
Comments
Post a Comment