【发布时间】:2016-07-16 16:00:57
【问题描述】:
我正在创建一个类型为多项选择(复选框)的 ListView,如下所示
var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemMultipleChoice);
attendanceListView.Adapter = adapter;
现在我想在从微调器中选择项目时检查一些复选框
ListView 被填充为
adapter.Add("Select All");
foreach (var item in studentInformation)
{
adapter.Add(item.studentName.ToString());
}
到这里为止,一切都是完美的。但是现在从 courseSpinner 中选择项目时出现问题
private void CourseSpinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
ListView list = (ListView)sender;
for (int count = 0; count < attendanceInformation.Count(); count++)
{
if (attendanceInformation[i].status == true)
{
selectedStudents[i] = attendanceInformation[i].studentId;
list.SetItemChecked(i, true);
}
else
{
list.SetItemChecked(i, false);
}
}
}
但它会引发异常:
System.InvalidCastException:指定的强制转换无效。
【问题讨论】:
-
在你的 CourseSpinner_ItemSelected 方法中,你能在控制台中写下“sender.GetType()”的值吗?
标签: listview xamarin.android android-spinner android-checkbox