私はスピナーを持っており、データバインディング機能を備えたスピナーにデータをロードします。私はXML(https://developer.android.com/topic/libraries/data-binding/index.html#expression_language)の文字列配列を宣言する方法を見つけようとしましたが、満足のいく結果は見つかりませんでした。Androidデータバインディングを使用してスピナーの文字列配列を設定できません
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:apps="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.util.SparseArray"/>
<variable
name="statuslist"
type="SparseArray<String>"/>
</data>
...
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/spn_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/spinner1"
android:layout_below="@+id/btn2"
android:entries="@{statuslist}"
apps:adapter="@{statusAdapter}"/>
</layout>
ビルド時に、次のエラーが表示されます。
エラー: ':app:dataBindingProcessLayoutsDebug'タスクの実行に失敗しました。
org.xml.sax.SAXParseException; systemId: file:/C:/Users/../app/build/intermediates/res/merged/debug/layout/testdialog.xml; lineNumber: 24; columnNumber: 30; The value of attribute "type" associated with an element type "null" must not contain the '<' character.
しかし、混乱しているものがあります。
- ウェブサイトのようにSparseArrayを使用しようとしましたが、私はAndroid StudioのXMLエディタで "Can not resolve sysmbol"を見つけました。
- ウェブサイトのスピナーデータバインディングに関する公式の指示がないので、スピナーの配列値を設定する正しい方法はわかりません。
build.gradleでデータバインディングを有効にしましたか? – anhtuannd
はい、build.gradleでデータバインディングを有効にします。ここに私のAndroid Studio(バージョン:2.1.2、JavaVersion:1.7)の情報があります –