[英]Checkbox.checked is not working in View Monodroid
I am new to mono for android. 我是Android新手。 I am trying to make a simple checkbox list where I can select my candidates, press a button to insert them to Database. 我正在尝试制作一个简单的复选框列表,从中可以选择我的候选人,然后按一个按钮将其插入数据库。 All is fine till here but the problem is with loading my checked values. 到这里一切都很好,但是问题在于加载我的检查值。 My checkboxes are always unchecked even if i explicitly put this.Checked = true; 即使我明确地放置了此复选框,我的复选框也始终处于未选中状态。
here is my code: 这是我的代码:
Loading listview: 加载列表视图:
var CandidatesList = FindViewById<ListView>(Resource.Id.lstVotingCandidates);
CandidatesVoteAdapter cva = new CandidatesVoteAdapter(this, MAE.Code.Utilities.CandidatesInfo.CurrentList);
CandidatesList.ChoiceMode = ChoiceMode.Multiple;
CandidatesList.Adapter = cva;
Adapter: 适配器:
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView; // re-use an existing view, if one is available
if (view == null) // otherwise create a new one
{
view = new Views.CandidateVoteItemView(context, items[position]);
}
return view;
}
View: 视图:
class CandidateVoteItemView : CheckBox
{
public MAE.MAEService.Candidate Candidate { get; protected set; }
public CandidateVoteItemView(Context context, MAE.MAEService.Candidate candidate) : base(context)
{
this.Text = candidate.FirstName; //Working
this.Checked = true;// (candidate.isChecked == 1) ? true : false;//Not Working
}
}
You can try this approach: 您可以尝试以下方法:
lv.SetItemChecked(1, true);
Taken from official xamarin site and check section 2.2 摘自xamarin官方网站并查看第2.2节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.