Ad
Android Which Attribute Set To Binding OnScrollChanged()
I want to execute onScrollChangeListner when binding views. But I don't know which attribute set to Android:.... in layout.
I create horizontal scrollview, write onScrollChangeListner, next I add this view to binding. Before I add view to binding, scrollview has execute listener and I saw changes in him. Maybe I must add this listener to layout? But I don't know how.
Code in class:
HorizontalScrollView horizontalScrollView = view.findViewById(R.id.scroll_view);
horizontalScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
.
. execute code
.
}
Code in layout:
<data>
<variable
name="sample"
type=Class with my method />
</data>
android:onScroll="@{() -> sample.onScrollChanged()}"
Found data binding errors. ****/ data binding error ****msg:Cannot find the setter for attribute 'android:onScroll' with parameter type lambda on android.widget.HorizontalScrollView. ****\ data binding error ****
Ad
Answer
you can do this with BindingAdapter
@JvmStatic
@BindingAdapter("onScrolled")
fun setOnScroll(horizontalScrollView: HorizontalScrollView) {
horizontalScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() { }
)
}
onScrolled="@{() -> sample.onScrollChanged()}"
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad