编译时出现以下错误:
BindingAdapter onOpacityValueChanged(android.widget.SeekBar,int,boolean): old values should be followed by new values. Parameter 2 must be the same type as parameter 3.
public void onOpacityValueChanged(SeekBar seekBar, int newOpacity, boolean fromUser) {
^
XML 代码是:
<SeekBar
android:id="@+id/soaring_forecast_seekbar_opacity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:min="0"
android:onProgressChanged="@{forecastDisplay::onOpacityValueChanged}"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="@+id/soaring_forecast_constraint_layout"
app:layout_constraintStart_toStartOf="@+id/soaring_forecast_constraint_layout"
app:layout_constraintTop_toBottomOf="@+id/soaring_forecast_image_time"/>
源代码是:
@BindingAdapter(value={"android:onProgressChanged"})
public void onOpacityValueChanged(SeekBar seekBar, int newOpacity, boolean fromUser) {
forecastOverlayOpacity = newOpacity;
appPreferences.setForecastOverlayOpacity(newOpacity);
stopImageAnimation();
displayForecastImageSet();
}
据我所知,代码与SeekBarBindingAdapter onProgressChanged 匹配。我错过了什么?
最佳答案
From what I can see the code matches to SeekBarBindingAdapter onProgressChanged. What am I missing?
- 您可以查看SeekBarBindingAdapter的源代码
###或者
- 您可以在 Android Studio 库中看到。
BindingAdapter onOpacityValueChanged(android.widget.SeekBar,int,boolean): old values should be followed by new values. Parameter 2 must be the same type as parameter 3. public void onOpacityValueChanged(SeekBar seekBar, int newOpacity, boolean fromUser) { ^
###@BindingAdapter 方法必须是静态的。
###最重要
您遵循的方式不正确。 @BindingAdapter
用于需要一些自定义实现的地方。请参阅documentation .
因此,从您的方法中删除 @BindingAdapter(value={"android:onProgressChanged"})
。
或者您可以使用 lambda 表达式使您的方法更加简单。
public void onOpacityValueChanged(int newOpacity) {
//something
}
和
android:onProgressChanged="@{(sb, value, fromUser)->forecastDisplay.onOpacityValueChanged(newValue)}"
关于android - 搜索栏数据绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52080871/