我正在尝试调用其余的 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) 我想使用绑定适配器设置文本。这是 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)
无需ViewModel()仅使用简单的类进行扩展,我就可以实现 LiveData 和 DataBinding 示例,但我在 google 开发人员文档中显示了扩展ViewModel()以创建 LiveData 对象。那么为什么我们需要扩展它呢?
https://developer.android.com/topic/libraries/architecture/livedata