I am currently trying to set a click listener to a LinearLayout
view in the .xml
layout file using data binding.
I have managed to get it to wo
You can handle any view click event like below. Hope it helps!
1) Create interface for handle click event like below.
interface OnClickHandlerInterface {
void onClick(View view)
}
2) Implement that click listener in action class as shown below
class MainActivity implements OnClickHanderInterface{
@Override
void OnClick(View view){
}
}
3) Now bind this interface in XML file.
4) Now register this interface in action class with use of binding object
mActivityMainBinding.clickHandler = this
5) Now set onClick on any which you want to set click listener. For you it's LinearLayout
6) Now handle click when your linearLayout clicked you can get click on interface which is implemented in action class.
@Override
void OnClick(View view){
switch(view.getId()){
case R.id.linearLayout:
// Handler click and do some actions
break;
}
}
6) As mentioned above you can get layout click by data binding. Hope it will work for you.
Thanks
Happy Coding!!