1

I'm struggling to make Android Binding Library to work with Kotlin. What I want to achieve is dispatch a onClick event to my Presenter class. What I've done was:

  1. Enable databinding on module's gradle file: dataBinding {enabled = true}
  2. Import databinding compiler: kapt 'com.android.databinding:compiler:2.0.0-beta6'
  3. Generate stubs: kapt {generateStubs = true}
  4. Implement method on MainPresenter.kt:

    fun onClickEditProfile () {
        log("method you hoped to get called was called")
        mView!!.getContext().snackbar("received event: onClickEditProfile via data binding, this is awesome").show()
    }
    
  5. Prepare layout:

    <layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <data>
            <variable
                name="presenter"
                type="br.com.tyllt.presenter.MainPresenter" />
        </data>
            <com.github.clans.fab.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="@{() -> presenter.onClickEditProfile()}"
                android:src="@drawable/ic_edit"
                app:fab_colorNormal="@color/colorPrimary"
                app:fab_colorPressed="@color/colorPrimaryDark"
                app:fab_hideAnimation="@anim/fab_scale_down"
                app:fab_label="Edit Profile"
                app:fab_size="mini" />
    </layout>
    

Problem is, when I generate the apk I get the followin exception:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method org.jetbrains.kotlin.annotation.RoundEnvironmentWrapper.getElementsAnnotatedWith, parameter a

Any idea?

1
  • Paste your build.gradle file Commented Jan 7, 2017 at 4:52

1 Answer 1

1

Well, after following this answer and taking care to use:

private fun initDataBinding() {
        val binding: ActivityLoginBinding = DataBindingUtil.setContentView(this, R.layout.activity_login)
        binding.presenter = mPresenter
    }

I was able to make it work. The problem was, I was initing the binding only using:

MainActivityBinding binding = MainActivityBinding.inflate(getLayoutInflater());

As pointed on Data Binding Library official page, which by some reason didnt work for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.