Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data binding - two way binding error #61

Open
nurjan84 opened this issue Aug 9, 2018 · 5 comments
Open

data binding - two way binding error #61

nurjan84 opened this issue Aug 9, 2018 · 5 comments

Comments

@nurjan84
Copy link

nurjan84 commented Aug 9, 2018

android:rating="@={estimateViewModel.rating}"

[kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors. ****/ data binding error ****msg:Cannot find the getter for attribute 'android:rating' with value type java.lang.Float on com.willy.ratingbar.ScaleRatingBar.

@williamyyu
Copy link
Owner

Hello @nurjan84 ,

Maybe you should use app:srb_rating, not android:rating
I haven't try it on data binding, so if there still have problem, please tell me.
Thank you.

@nurjan84
Copy link
Author

Hello! Same error with app:srb_rating

[kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors. ****/ data binding error ****msg:Cannot find the getter for attribute 'app:srb_rating' with value type java.lang.Float on com.willy.ratingbar.ScaleRatingBar.

@williamyyu
Copy link
Owner

Hi,
Sorry that I've been a little bit busy these days,
I'll try to find out the problem when I have more free time.
Thank you for issue this problem!

@bean-liu
Copy link

bean-liu commented Aug 8, 2020

add ScaleRatingBarBindingAdapter.java to your project
xml use app:rating="@={estimateViewModel.rating}"


import androidx.databinding.BindingAdapter;
import androidx.databinding.InverseBindingListener;
import androidx.databinding.InverseBindingMethod;
import androidx.databinding.InverseBindingMethods;

import com.willy.ratingbar.BaseRatingBar;
import com.willy.ratingbar.ScaleRatingBar;

@InverseBindingMethods({
        @InverseBindingMethod(type = ScaleRatingBar.class, attribute = "rating"),
})
public class ScaleRatingBarBindingAdapter {
    @BindingAdapter("android:rating")
    public static void setRating(RatingBar view, float rating) {
        if (view.getRating() != rating) {
            view.setRating(rating);
        }
    }
    @BindingAdapter(value = {"onRatingChanged", "ratingAttrChanged"},
            requireAll = false)
    public static void setListeners(ScaleRatingBar view, final ScaleRatingBar.OnRatingChangeListener listener,
            final InverseBindingListener ratingChange) {
        if (ratingChange == null) {
            view.setOnRatingChangeListener(listener);
        } else {
            view.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
                @Override
                public void onRatingChange(BaseRatingBar ratingBar, float rating, boolean fromUser) {
                    if (listener != null) {
                        listener.onRatingChange(ratingBar, rating, fromUser);
                    }
                    ratingChange.onChange();
                }
            });
        }
    }
}

@konopkoman
Copy link

Also have the issue with the following: app:srb_rating="@{rating}"

Cannot find a setter for <com.willy.ratingbar.BaseRatingBar app:srb_rating> that accepts parameter type 'java.lang.Float'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants