Databinding with SeekBar's onProgressChanged not working

Siddhpura Amit :

I am using Seekbar with DataBinding and below is my code

<data>

    <variable
        name="generatePasswordModel"
        type="android.account.model.GeneratePasswordModel" />

</data>

 <SeekBar
       android:id="@+id/sbPasswordLength"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_marginLeft="10dp"
       android:layout_marginRight="10dp"
       android:layout_weight="1"
            android:onProgressChanged="@{generatePasswordModel.onValueChanged()}"
       android:max="20"
       android:min="4" />

and Model class is below

data class GeneratePasswordModel(
    private var seekValue: String,
    private var seekDisplay: String
) : BaseObservable() {


    var mSeekDisplay: String
        @Bindable get() = seekDisplay
        set(value) {
            seekDisplay = value
            notifyPropertyChanged(BR.mSeekDisplay)
        }

    fun onValueChanged(seekBar: SeekBar, progresValue: Int, fromUser: Boolean) {
        mSeekDisplay = progresValue.toString()
    }

}

But I am getting following error while build an apk

ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1/Users/amitsiddhpura/Documents/.../app/build/generated/source/kapt/debug/.../android/DataBinderMapperImpl.java:18: error: cannot find symbol


                                                 import android.databinding.ActivityGeneratePasswordBindingImpl;
22:40:06.432 [ERROR] [system.err]                                         ^
22:40:06.432 [ERROR] [system.err]   symbol:   class ActivityGeneratePasswordBindingImpl
Jacob Collins :

Check out the top answer on this question: Seekbar databinding error

It appears that you need to specify the arguments in your XML:

android:onProgressChanged="@{(seekBar, value, fromUser)->generatePasswordModel.onValueChanged(seekBar, value, fromUser)}}

But, since you're not actually using the seekBar or the fromUser in your Kotlin code, you could modify your function's definition like so:

fun onValueChanged(progresValue: Int) {
        mSeekDisplay = progresValue.toString()
    }

And then the XML would look like:

android:onProgressChanged="@{(seekBar, value, fromUser)->generatePasswordModel.onValueChanged(value)}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=320074&siteId=1