无法使用Android数据绑定为微调器设置字符串数组 [英] Cannot set string array for spinner using Android data binding

查看:76
本文介绍了无法使用Android数据绑定为微调器设置字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个微调器,我想通过数据绑定功能将数据加载到微调器中.我试图找到在XML中声明字符串数组的方法( https://developer.android.com/topic/libraries/data-binding/index.html#expression_language ),但找不到满意的结果.

I have a spinner now and I want to load the data to the spinner with data binding feature. I tried to find the way to declare the string array in the XML(https://developer.android.com/topic/libraries/data-binding/index.html#expression_language) but no satisfied result is found.

<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>

在构建时,显示以下错误.

When it is build, the following error is shown.

错误:任务':app:dataBindingProcessLayoutsDebug'的执行失败.

Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'.

org.xml.sax.SAXParseException; systemId:文件:/C:/用户/../app/build/intermediates/res/merged/debug/layout/testdialog.xml; lineNumber:24; columnNumber:30;与元素类型"null"相关联的属性"type"的值不得包含<"字符.

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.

但是,有些困惑.

  1. 当我尝试使用网站上显示的SparseArray时.我在Android Studio XML编辑器中找到无法解析sysmbol".
  2. 我不知道这是设置微调器数组值的正确方法,因为网站上没有关于微调器数据绑定的官方说明.

推荐答案

SparseArray<String>更改为SparseArray&lt;String&gt;.

这篇关于无法使用Android数据绑定为微调器设置字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆