0

I've created an utility controller and instantiated it through the xml (CyborgView). So far so good.
I got stuck, however, when I wanted to use it... How do I get a reference of that controller from the xml?
Note that my goal here is to use multiple controllers of the same type.

MrGuy
  • 654
  • 1
  • 5
  • 18
  • 1
    What is a utility controller? and did you try to use the getControllerById API? – TacB0sS Aug 26 '17 at 17:42
  • It's a control that I want to use multiple times in the same layout. Where do I get the controller id from? – MrGuy Aug 26 '17 at 17:55
  • 1
    Its not a controller id, its the **view id** of the CyborgView in your xml, that refers to the controller you want. – TacB0sS Aug 26 '17 at 17:59

1 Answers1

1

In Cyborg 0.8.11(available soon) you can use the ViewIdentifier annotation to inject controllers and not only views.

In Cyborg 0.8.10 and below: You can get controllers in a pretty similar way to getting views, you give the CyborgView an id just like you'd give a view, and then get the controller using that id:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                  xmlns:cyborg="http://schemas.android.com/apk/res-auto"
                                  android:layout_width="match_parent"
                                  android:layout_height="match_parent"
                                  android:orientation="vertical">

                    <com.nu.art.cyborg.core.CyborgView
                            android:id="@+id/CV_MyController"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            cyborg:controller="com.me.myself.i.MyController"/>
</LinearLayout>

And then in the controller itself, override the extractMembers() function and inside it get the controller:

    private MyController myController;

    @Override
    protected void extractMembers() {
         myController = getControllerById(R.id.CV_MyController);
    }

To use multiple instances of the same controller, you can differ between them with the id attribute.

Matan Koby
  • 232
  • 1
  • 11