Android 自定义项的数据绑定列表
如何将自定义项列表绑定到ListView或RecyclerView?仅使用Android默认值数据绑定(无外部库)Android 自定义项的数据绑定列表,android,android-databinding,Android,Android Databinding,如何将自定义项列表绑定到ListView或RecyclerView?仅使用Android默认值数据绑定(无外部库) 请签出此库: 此库允许将自定义对象的ObservableList绑定到RecyclerView。如果这对某人有帮助,我觉得您正在寻找的是来自数据绑定功能的绑定适配器 更多信息可在此处找到: 这将允许您定义可在xml中使用的自定义属性,并传递所需项目的列表 @BindingAdapter("nameOfProperty") public static void loadImage
请签出此库:
此库允许将自定义对象的ObservableList绑定到RecyclerView。如果这对某人有帮助,我觉得您正在寻找的是来自数据绑定功能的绑定适配器
更多信息可在此处找到:
这将允许您定义可在xml中使用的自定义属性,并传递所需项目的列表
@BindingAdapter("nameOfProperty")
public static void loadImage(ListView listView, List listOfString) {
// do the actual logic here
}
这可以在xml中使用,比如app:nameofproperty=“@{listOfString}”
我正在阅读android数据绑定指南,但我认为这是一个很好的问题,所以我把它带来了up@nmtuan:您可以添加更多关于您使用数据绑定实际要执行的操作的详细信息吗?@AndiGeeky我只希望ListView或RecyclerView显示项目集合,可以是任何内容,如“类消息{String content}”,如WPF或窗口窗体中您在集合类型控件上有DataSource或ItemsSource,我在android上找不到类似的属性可以“绑定”@nmtuan:你是在说定制设计还是定制数据?他不是在找library@Trinity当然,最好(一次又一次地)重新发明轮子。您总是可以查看源代码并找到有趣的部分。
<ListView ItemsSource="{Binding Path=UserCollection}">
<ListView.ItemTemplate>
<!--Populate template with each user data-->
<DataTemplate>
<WrapPanel>
<!--Bind to user.Name-->
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Text="{Binding Age}" FontWeight="Bold" />
<TextBlock Text="{Binding Mail}" />
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
@BindingAdapter("nameOfProperty")
public static void loadImage(ListView listView, List listOfString) {
// do the actual logic here
}