小编Pur*_*iya的帖子

无法使用 retofit 解析对 kotlin 数据类的 xml 响应

我正在尝试调用其余的 api,它会给我 xml 响应。我正在使用 simplexml 转换器工厂进行改造,将 xml 解析为 kotlin 数据类。以下是 api 的 xml 响应:

<category>
    <api-version>1.0</api-version>
    <books>
        <list>
            <result>
                <author>Hello1</author>
                <brief>Hii</brief>
            </result>
            <result>
                <author>Hello2</author>
                <brief>Hii2</brief>
            </result>
        </list>
    </books>
</category> 
Run Code Online (Sandbox Code Playgroud)

下面是我的 kotlin 数据类

data class CategoryResponseModel(
        @field:Element(name = "api-version", required = false)
        @param:Element(name = "api-version", required = false)
        val apiVersion: String? = null,

        @field:Element(name = "books", required = false)
        @param:Element(name = "books", required = false)
        val books: Books? = null
)

data class Books(
        @field:Element(name = "list", required = false)
        @param:Element(name …
Run Code Online (Sandbox Code Playgroud)

android xml-parsing kotlin retrofit

7
推荐指数
1
解决办法
381
查看次数

Android资源链接在绑定适配器数据绑定时失败

我想使用绑定适配器设置文本。这是 MyBindingAdapter.kt

@BindingAdapter("android:setTitle")
fun setTitle(textView : TextView,text: String){
        textView.text = text
}
Run Code Online (Sandbox Code Playgroud)

在activity_table.xml中我像这样使用了setTitle

  <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_weight="1"
            android:gravity="center"
            android:setTitle="Hello word"/>
Run Code Online (Sandbox Code Playgroud)

我在编译时遇到以下错误 我在编译时遇到以下错误

data-binding android kotlin

6
推荐指数
1
解决办法
1036
查看次数

为什么我们需要为 DataBinding 和 LiveData 扩展“ViewModel()”来创建 LiveData 对象

无需ViewModel()仅使用简单的类进行扩展,我就可以实现 LiveData 和 DataBinding 示例,但我在 google 开发人员文档中显示了扩展ViewModel()以创建 LiveData 对象。那么为什么我们需要扩展它呢?

https://developer.android.com/topic/libraries/architecture/livedata

android kotlin android-livedata mutablelivedata

1
推荐指数
1
解决办法
848
查看次数