xamarin.android中是否有相当于listView.itemssource?
我正在开发一个 xamarin.android 项目,我需要将组件列表链接到布局列表视图以显示此组件列表。经过一番研究,我发现要做到这一点,您需要某种适配器,并且似乎有很多与创建适配器以在列表视图中显示某些列表相关的代码。 我知道在 xamarin.forms 中有一个 ListView 的 ItemsSource 属性,这使得生活更轻松,有没有与 xamarin.android 中类似的东西? 我对这一切都很陌生,所以如果我错过了一些东西,我很抱歉。提前致谢!
I am working on an xamarin.android project, where I need to link a list of components to the layout listview to display this list of components. After some research, I found out that to do that you need some kind of adapter, and there seems to be a lot of code associated with creating an adapter to display some list in the listview.
I know that in xamarin.forms there is an ItemsSource propery of the ListView which makes life easier, is there anything similar to that in xamarin.android?
I am new to all that so if I'm missing something I am sorry. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于ListView中的简单项目,您可以参考文档使用数据填充Xamarin.android listView 。
显示的项目是简单的字符串列表。
如果要如下图所示自定义listView的外观,则可以参考文档用xamarin.android自定义ListView的外观。

为此,您可以参考文档用xamarin.android自定义ListView的外观。
步骤是:
1。将listView添加到活动布局
2.创建自定义行布置
另一个AXML布局文件以包含每行的自定义布局,以显示在列表视图中。
3.引用自定义行视图
自定义适配器示例的实现在
homescreenadapter.cs
中。关键方法是getView
它在其中使用资源IDresource.layout.customview
加载自定义AXML,然后在返回视图中的每个控件上设置属性。显示完整的适配器类(TableItem
是项目模型):4。引用活动中的自定义listView
您可以在此处获取完整示例: https://github.com/xamarin/monodroid-samples/tree/main/main/main/customrowview 。
For simple item in Listview,you can refer to document Populating a Xamarin.Android ListView with data , just as Jason mentioned.
The displayed items are simple string list.
If you want to customize a ListView's appearance just as the following image shows, you can refer to document Customizing a ListView's Appearance with Xamarin.Android.

For this, you can refer document Customizing a ListView's Appearance with Xamarin.Android .
The steps is:
1.Adding a ListView to an Activity Layout
2.Creating a Custom Row Layout
Another AXML layout file is required to contain the custom layout for each row that will appear in the list view.
3.Referencing a Custom Row View
The implementation of the custom adapter example is in
HomeScreenAdapter.cs
. The key method isGetView
where it loads the custom AXML using the resource IDResource.Layout.CustomView
, and then sets properties on each of the controls in the view before returning it. The complete adapter class is shown(TableItem
is the item model):4.Referencing the Custom ListView in the Activity
You can get the full sample here: https://github.com/xamarin/monodroid-samples/tree/main/CustomRowView .