williamyyu / SimpleRatingBar

A simple RatingBar that you can easier to customize image and animations
MIT License
1.37k stars 152 forks source link

data binding - two way binding error #61

Open nurjan84 opened 6 years ago

nurjan84 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 4 years ago

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 commented 1 year ago

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

Cannot find a setter for that accepts parameter type 'java.lang.Float'