Using lambda expression and a Switch
:
public void onCheckedChanged(boolean checked) {
// implementation
}
XML file:
<android.support.v7.widget.SwitchCompat
android:onCheckedChanged="@{(switch, checked) -> item.onCheckedChanged(checked)}"
...
/>
Where item
is the class that implements onCheckedChange
method and is imported to the XML file like this:
<data>
<variable
name="item"
type="yourClass"/>
</data>
Related Contents:
- Data Binding class not generated
- I want to concat two strings for a TextView in android, Data Binding Api
- How can I style an Android Switch?
- Android : Difference between DataBinding and ViewBinding
- onCheckedChanged called automatically
- What are the pros and cons of android data-binding?
- How to use data-binding in Dialog?
- android data binding with a custom view
- Android Data Binding @BindingConversion failure for int to string
- Android – DataBinding – How and when the Binding classes will be generated?
- How to change the size of a Switch Widget
- ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1
- How to custom switch button?
- Can’t resolve Android databinding class
- Data binding expression not compiling
- Android DataBinding where to get context?
- Glide showing error: Failed to find GeneratedAppGlideModule
- Data Binding Android – Type parameter T has incompatible upper bounds : ViewDataBinding and MainActivity
- Android Switch widget textOn and textOff not working in Lollipop
- Using DataBinding library for binding events
- data binding – safeUnbox warning
- cannot find symbol BR in android data binding
- Change Switch state without animation
- What is the simplest and most robust way to get the user’s current location on Android?
- No matching client found for package name (Google Analytics) – multiple productFlavors & buildTypes
- Android webview & localStorage
- Which Architecture patterns are used on Android? [closed]
- Android Paint: .measureText() vs .getTextBounds()
- Can I change the Android startActivity() transition animation?
- Android Studio – Where can I see callstack while debugging an android app?
- What causes signal ‘SIGILL’?
- How and where to use Transformations.switchMap?
- How to shrink code – 65k method limit in dex
- Action Required: Your app is not compliant with Google Play Policies , what is the solution?
- What are best practices for using SVG icons on Android?
- Android accelerometer not working when screen is turned off
- How SurfaceHolder callbacks are related to Activity lifecycle?
- How do I specify eg. Roboto-Medium or Roboto-Black in styles.xml
- Decrease image size without losing its quality in android
- How do the pieces of Android’s (2D) Canvas drawing pipeline fit together?
- Image Uri to bytesarray
- How to avoid keyboard pushing layout up on Android react-native
- Can you change min. API level for your Android app in Eclipse?
- Error initializing Cordova: Class not found
- Android – Inner element must either be a resource reference or empty
- Android Transparent TextView?
- Iterate through rows from Sqlite-query
- How to get Android Thread ID?
- How to set fixed aspect ratio for a layout in Android
- How to add a line at the bottom of spinner as like edittext in android