Search code examples
androidrobobinding

Enabled attribute not working in button


I'm using this link (http://robobinding.github.io/RoboBinding/old_binding_attributes.html) to check which attributes are available.

I'm trying to use the "enable" attribute in a button like this:

<Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="start"
     android:id="@+id/start_button"
     bind:enable="{canStart}" />

But whenever I run the application, I'm getting the following error:

enabled: Unrecognized attribute 'enabled'
    -------------------------The first error stack trace-----------------------
    enabled: Unrecognized attribute 'enabled'
            at org.robobinding.PendingAttributesForViewImpl.getResolutionErrors(PendingAttributesForViewImpl.java:43)
            at org.robobinding.binder.BindingAttributeResolver.resolve(BindingAttributeResolver.java:39)
            at org.robobinding.binder.BindingViewInflater.resolveAndAddViewBindingAttributes(BindingViewInflater.java:90)
            at org.robobinding.binder.BindingViewInflater.onViewCreated(BindingViewInflater.java:85)
            at org.robobinding.ViewFactory.notifyViewCreatedIfNotNull(ViewFactory.java:65)
            at org.robobinding.ViewFactory.onCreateView(ViewFactory.java:58)
            at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
......

If I change to "visibility" attribute it works fine.

Is the "enabled" attribute supported in buttons?


Solution

  • You should use new 'API and Binding Attributes JavaDocs' link from RoboBinding home page.

    All simpleOneWayProperties are removed from RoboBinding framework, as they can be declared when required. The following example can be found from RoboBinding Gallery project.

    @ViewBinding(simpleOneWayProperties = {"enabled"})
      public class ViewBindingForView extends CustomViewBinding< View> {
    }
    

    register it:

    reusableBinderFactory = new BinderFactoryBuilder()
      .add(new ViewBindingForView().extend(View.class))
      .build();
    

    View Visibility is an OneWayMultiTypeProperty, as it support Boolean and Integer. Source code here - https://github.com/RoboBinding/RoboBinding/blob/develop/framework/src/main/java/org/robobinding/widget/view/ViewBindingForView.java

    For supported attribute bindings for a widget, except for looking into javadoc, you can also find the implemented binding information in ViewBinding implementation, e.g., RatingBar - https://github.com/RoboBinding/RoboBinding/blob/develop/framework/src/main/java/org/robobinding/widget/ratingbar/RatingBarBinding.java