I was able to complete this challenge, but not using data binding and it’s driving me nuts. In my layout I am using the onProgressChanged attribute inside the seekbar element but when I bind it to a method in my viewmodel or elsewhere I get a “Cannot Resolve Type” error. I’m not sure what I am missing, or how to properly implement the SeekBarBindingAdapter I guess.
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.bignerdranch.android.beatbox.SoundViewModel"/>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<SeekBar
android:id="@+id/bottom_speed_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
style="@style/Widget.AppCompat.SeekBar"
android:max="100"
android:onProgressChanged="@{(seekbar, progress, fromUser)-> viewModel.onSeekBarMove}"
/>
</FrameLayout>
</layout>
Here Is my method that I can’t get to bind, using the same parameters as the onProgressChanged method inside the seekbar listener.
...
public void onSeekBarMove(SeekBar seekBar, int progress, boolean fromUser){
//Set playback rate
return;
}
And here is where the attributes are specified in the SeekBarBindingAdapter.java class
...
@BindingAdapter(value = {"android:onStartTrackingTouch", "android:onStopTrackingTouch",
"android:onProgressChanged", "android:progressAttrChanged"}
...
EDIT: I am now getting this error after changing the layout to:
android:onProgressChanged="@{(seekbar, progress, fromuser) -> viewModel.onSeekBarMove(seekbar, progress, fromuser)}"
Debugging data binding has kind of been a nightmare. I got it to compile and run earlier by using he viewModel:onSeekBarMove syntax but the listener wasn’t working.
C:\Users\pstev\Documents\BeatBox\app\build\generated\source\apt\debug\com\bignerdranch\android\beatbox\databinding\FragmentBeatBoxBinding.java:131: error: cannot find symbol
callbackArg_0.onSeekBarMove(callbackArg_1, callbackArg_2, com.bignerdranch.android.beatbox.SoundViewModel);
^
symbol: class beatbox
location: package com.bignerdranch.android
Note: C:\Users\pstev\Documents\BeatBox\app\src\main\java\com\bignerdranch\android\beatbox\BeatBox.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error