我正在尝试使用新的Android数据绑定库,并尝试使用所选值填充微调器时出现以下错误.
错误消息(在Android Studio中编译期间):
错误:任务':app:compileDebugJavaWithJavac'的执行失败.java.lang.RuntimeException:发现数据绑定错误.****/数据绑定错误****消息:无法找到参数类型为java.lang.String的属性'app:selection'的setter.file:/Users/ove/Code/AndroidStudio/Samples/Receipts/app/src/main/res/layout/dialogfragment_inputamount_db.xml loc:40:29 - 40:44****\data binding error****
我的布局文件看起来如下(不完整):
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="receipt"
type="com.example.model.Receipt" />
</data>
</LinearLayout>
<Spinner
android:layout_width="wrap_content"
android:id="@+id/currency"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:entries="@array/currency_array"
app:selection="@{receipt.currency}" />
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
那些设法获得数据绑定与旋转器一起工作的人?
奥维
我无法使用2way数据绑定与微调器一起工作.我在这里导出了我的android工作室项目 - https://github.com/asatyana/Spinner2WayDataBinding
感谢专家的帮助
这是我的活动布局
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="myModel"
type="com.example.spinner.model.SpinnerModel" />
</data>
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.spinner.MainActivity"
tools:showIn="@layout/activity_main">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@{myModel.countries}"
app:selection="@{myModel.countryIdx}"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/spinner"
android:text="@{myModel.country}" />
</RelativeLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
我的模特
public class SpinnerModel extends BaseObservable{
private String [] countries;
private int countryIdx;
private String country;
public SpinnerModel()
{
List<String> allCountries = new ArrayList<String>();
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
Locale obj = …Run Code Online (Sandbox Code Playgroud)