I create custom view and use it in some xml activity then set android:onClick="buttonOnClick"
. I defined buttonOnClick
as public
and write it in its activity and set tools:context
.
Activity.java
public void buttonOnClick(View view) {
validate(view);
}
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
...
tools:context="com.test.myapp.Activity">
<com.test.myapp.GifImageViewComp
....
android:onClick="buttonOnClick" />
it's working on Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
but in other OS version, custom view xml onclick attribute try to find handler from view class instead of activity.
I don't want use implementation of onClick or setOnClickListener on every view, i want use onClick in layout of activity