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可以滚动?