在我的应用程序中,我有一个列表活动,您可以在其中检查列表中的多个项目,如何在下次打开列表活动时检查已检查的项目?我认为做到这一点的方法是使用getview,但我不知道如何在我的课堂上实现它,因为我没有使用自定义listadapter,如果有人能告诉我那会很棒
下面是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Linq;
namespace BoostITAndroid
{
[Activity(Label = "My Activity")]
public class Selector : ListActivity
{
int[] numlist = new int[45];
String[] Options;
int[] OptionsID;
String item;
int counter = 0;
Button save, cancel;
int vehicleId;
int category;
private List<AvailableFeatures> list;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
List<Makes> listmakes = VehicleAssetsDB.GetMakes();
Options = new String[listmakes.Count];
OptionsID = new int[listmakes.Count];
Options = listmakes.Select(Makes => Makes.Make).ToArray();
OptionsID = listmakes.Select(Makes => Makes.ID).ToArray();
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, Options);
}
}
}
下面是我的 onclicklistener
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
l.ChoiceMode = ChoiceMode.Multiple;
Android.Util.SparseBooleanArray checkedItems = l.CheckedItemPositions;
if (!checkedItems.Get(position))
{
l.SetItemChecked(position, false);
}
if (checkedItems.Get(position))
{
l.SetItemChecked(position, true);
}
}