0

I'm trying to build Android app in Kotlin using dataBinding and when I'm trying to compile this code

@Bindable
var progress:Int=1

@NotNull
@InverseBindingAdapter(attribute = "progress")
 fun  SeekBar.getProgress():Int{
    return this.progress
}

@BindingAdapter(value = ["progressAttrChanged"])
fun setListeners(seekBar: SeekBar,inverseBindingListener: InverseBindingListener){
    var listener=object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(seekBar: SeekBar?, Progress: Int, fromUser: Boolean) {
            progress=Progress
            mBeatBox.mRange=progress/66.67 as Float
            inverseBindingListener.onChange()
        }

        override fun onStartTrackingTouch(seekBar: SeekBar?) {

        }

        override fun onStopTrackingTouch(seekBar: SeekBar?) {

        }
    }
    seekBar.setOnSeekBarChangeListener(listener)
}

I get this errors https://ibb.co/cBHRwx.

Here is view of modelView

 <data>
    <variable
        name="viewModel"
        type="com.bignerdranch.android.beatboxkotlin.Models.BeatBoxViewModel"/>
</data>
....
 <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:text="progres"
        android:gravity="center"
        android:layout_weight="9"/>
    <android.support.v7.widget.AppCompatSeekBar
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="9"
        app:progress="@={viewModel.progress}"/>

How can I solve this?

1
  • Please post your error in text, not an external image Commented Apr 29, 2018 at 20:40

2 Answers 2

2

I solved this error in this way

Updated viewModel `

var progress:Int=mBeatBox.mRange.toInt()
@Bindable set(value){field=value;notifyChange()}
@Bindable get()=field

fun getEditListener():SeekBar.OnSeekBarChangeListener{
var listener=object: SeekBar.OnSeekBarChangeListener{
        override fun onProgressChanged(seekBar: SeekBar?, Progress: Int, fromUser: Boolean) {
            progress=Progress
            mBeatBox.mRange=(progress/66.67).toFloat()
        }
        override fun onStartTrackingTouch(seekBar: SeekBar?) {
        }
        override fun onStopTrackingTouch(seekBar: SeekBar?) {
        }
    }
    return listener
}`

And View looks like:

 <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:text="progress"
        android:gravity="center"
        android:layout_weight="9"
        android:text="@{String.valueOf(viewModel.progress)}"/>
    <android.support.v7.widget.AppCompatSeekBar
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="9"
        app:OnSeekBarChangeListener="@{viewModel.EditListener}"/>
Sign up to request clarification or add additional context in comments.

1 Comment

Mark your answer as solution to close the question please :)
0

Not sure exactly what your error is pointing to, but looks like there's already a SeekbarBindingAdapter defined in the library, so you probably don't need to define your own. If you want to update things when progress changes, override set or use ObservableInt with an OnPropertyChangedCallback

1 Comment

I have just solved my problem in other way but thank you for suggestions.

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.