androidkotlinseekbarandroid-seekbar

android:onProgressChanged doesn't exists in seekbar


I am trying to listen to seekbar's progress change from a viewmodel using dataBinding and LiveData but the android:onProgressChanged doesn't exists in the xml view of the seekbar. Previously i was listening to it's progress programmatically from an activity but i can't do that now.

Can anyone tell me what to do? The main thing i want is to listen to seekbar's progressChange in the viewmodel using LiveData.

Here's my SeekBar:

<SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:onProgressChanged=""         // doesn't exists
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:max="200"
        android:progressDrawable="@drawable/custom_seekbar"
        android:thumb="@drawable/thumb_bg"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView11" />

Solution

  • Can you not expose a binding against 'progress' like this

    <SeekBar
      android:id="@+id/seek_bar"
      android:progress="@={viewModel.value}"
      ...
    

    That way you can observe changes of viewModel.value