Calligraphy
Calligraphy copied to clipboard
xml android:onClick not working
Hi,
when I add this snippet to the activity class to wrap the context, the xml android:onClick does not work.
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
I mean it throws this exception
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: java.lang.IllegalStateException: Could not find a method OnDeleteBtnClick(View) in the activity class uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper for onClick handler on view class com.rey.material.widget.FloatingActionButton with id 'optionView'
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.view.View$1.onClick(View.java:3956)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at com.rey.material.widget.RippleManager.run(RippleManager.java:85)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at com.rey.material.widget.RippleManager.onClick(RippleManager.java:79)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.view.View.performClick(View.java:4640)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.view.View$PerformClick.run(View.java:19421)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.os.Looper.loop(Looper.java:146)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5602)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at dalvik.system.NativeStart.main(Native Method)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: Caused by: java.lang.NoSuchMethodException: OnDeleteBtnClick [class android.view.View]
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at java.lang.Class.getConstructorOrMethod(Class.java:472)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at java.lang.Class.getMethod(Class.java:857)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: at android.view.View$1.onClick(View.java:3949)
07-12 18:50:11.150 15984-15984/com.shygunsys.pocketcyber W/System.err: ... 13 more
somehow wrapping the context prevents the system in looking correct class for onClick method since as soon as I comment the attachBaseContext override, everything start working fine
Haha, OK amazing that this hasn't come up before. I'll be honest, not sure I really care about fixing this.
For now don't use android:onClick. Your XML files are just view's they shouldn't be calling into your code that's very fragile.
For now don't use android:onClick. Your XML files are just view's they shouldn't be calling into your code that's very fragile.
@chrisjenx The new data binding API actually advocates this with the MVVM pattern.
That's a very very different. Also, personal opinion. I wouldn't use data binding either.
On Wed, 27 Jul 2016, 15:41 Jon Andersen, [email protected] wrote:
For now don't use android:onClick. Your XML files are just view's they shouldn't be calling into your code that's very fragile.
@chrisjenx https://github.com/chrisjenx The new data binding API actually advocates this with the MVVM pattern.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/305#issuecomment-235606784, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsamaPaCrGKQRcI3bOLVpWqK9GFDbks5qZ24ngaJpZM4JKcjF .
@jonandersen have you tried something like 'android:onClick="@{() -> handler.doSomething()}" I use this all the time and does not conflict with CalligraphyContextWrapper
Yes, I should point out DataBinding does work.
On Wed, 27 Jul 2016, 15:56 David García, [email protected] wrote:
@jonandersen https://github.com/jonandersen have you tried something like 'android:onClick="@{() -> handler.doSomething()}" I use this all the time and does not conflict with CalligraphyContextWrapper
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/305#issuecomment-235611711, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsWksJj_RyOTLGivxABdndWj_QkiOks5qZ3GUgaJpZM4JKcjF .
My bad about this had missed to annotate one of the calls properly and it wasn't calling the data binding method. Works fine with data binding. Thanks for all the work with the library