因此,我一直在使用複選框的listview查看應用程序,我注意到當我選擇一個項目時,當我向下滾動第一個項目時,在向下滾動完整頁面後,也會選中該複選框。我有一種感覺,這是由於重新查看意見,但我很好奇這個解決方案。我曾嘗試添加一個視圖,但這並沒有解決問題。只是想知道我錯過了什麼。代碼適配器上的getview低於:帶有複選框的列表視圖正在檢查多個複選框
public override Android.Views.View GetView(int position, Android.Views.View convertView, ViewGroup parent)
{
Android.Views.View view = convertView;
if (view == null)
{
view = context.LayoutInflater.Inflate(Resource.Layout.GroupTimeTrackerTemplate, parent, false);
}
tblWorkers item = this[position];
view.FindViewById<TextView>(Resource.Id.UserNameTextView).Text = this[position].nWorkerFirstname + " " + this[position].nWorkerLastname;
view.FindViewById<TextView>(Resource.Id.StatusTextView).Text = this[position].nStatusShort;
view.FindViewById<TextView>(Resource.Id.UserRoleTextView).Text = this[position].nTitle;
CheckBox chkSelect = view.FindViewById<CheckBox>(Resource.Id.ChkSelect);
chkSelect.Tag = item.nWorkerFirstname + " " + item.nWorkerLastname;
chkSelect.SetOnCheckedChangeListener(null);
chkSelect.SetOnCheckedChangeListener(new CheckChangeListener(this.context));
return view;
}
private class CheckChangeListener : Java.Lang.Object, CompoundButton.IOnCheckedChangeListener
{
private Activity activity;
public CheckChangeListener(Activity activity)
{
this.activity = activity;
}
public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
{
if (isChecked)
{
string name = (string)buttonView.Tag;
string text = string.Format("{0} Checked.", name);
Toast.MakeText(this.activity, text, ToastLength.Short).Show();
}
}
}
我已經做了Java和C#,他們都非常類似的,雖然Xamarin並不是很多例子。令人費解的是,我使用的是我傳入的實際列表,這是ObervableCollection,所以位置不應該成爲問題,但我想是的。你能舉一個Java例子嗎? – yams