C# 如何从ListView中获取选中项?

C# 如何从ListView中获取选中项?,c#,android,android-layout,listview,C#,Android,Android Layout,Listview,我有一个带有复选框的自定义列表视图,并用列表中的数据填充它。我在考虑如何接收已检查的项目,但基本上找不到解决方案。是否可以像这样使用列表视图,或者我应该自定义列表视图?有什么想法吗?提前谢谢 以下是我试图处理的代码: public string content; ListView productsListView; List<Product> _productsList = ProductsFromXml();

我有一个带有复选框的自定义
列表视图
,并用
列表中的数据填充它。我在考虑如何接收已检查的项目,但基本上找不到解决方案。是否可以像这样使用
列表视图
,或者我应该自定义
列表视图
?有什么想法吗?提前谢谢

以下是我试图处理的代码:

         public string content;
         ListView productsListView; 

         List<Product> _productsList = ProductsFromXml();

        //list for checked items (not yet)
        List<Product> checkedProducts = new List<Product>();

        //creating a ListView within our products
        productsListView = FindViewById<ListView>(Resource.Id.listView1);
        productsListView.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemMultipleChoice, _productsList);
        productsListView.ChoiceMode = ChoiceMode.Multiple;  
公共字符串内容;
列表视图产品列表视图;
列表_productsList=ProductsFromXml();
//已检查项目的列表(尚未)
List checkedProducts=新列表();
//在我们的产品中创建ListView
productsListView=FindViewById(Resource.Id.listView1);
productsListView.Adapter=new ArrayAdapter(这个,Android.Resource.Layout.SimpleListedMultipleChoice,\u productsList);
productsListView.ChoiceMode=ChoiceMode.Multiple;

产品
对象上创建一个属性,如
bool Checked
,并在
项目点击
事件中将其设置为
true/false

然后,您可以浏览列表并查看选择了哪些项目

演示如何侦听由
阵列适配器支持的
列表视图
的单击事件

您的
活动
需要从
列表活动
继承,然后您可以重写

OnListItemClick (ListView l, View v, int position, long id)

并使用
int position
参数索引
产品
列表,并将值设置为
真/假
以指示选择。

这应该会有所帮助:我有一个名为
产品
的类。所以我应该在那里创建一个bool属性?如果我想让我的ListView可以滚动?