复选框.checked在View Monodroid中不起作用

本文关键字:不起作用 Monodroid View checked 复选框 | 更新日期: 2023-09-27 18:17:52

我是android mono的新手。我试图使一个简单的复选框列表,在那里我可以选择我的候选人,按下一个按钮,将它们插入到数据库。一切都很好,直到这里,但问题是加载我的检查值。我的复选框总是未选中的,即使我显式地放置this。

下面是我的代码:

加载视图:

    var CandidatesList = FindViewById<ListView>(Resource.Id.lstVotingCandidates);
    CandidatesVoteAdapter cva = new CandidatesVoteAdapter(this, MAE.Code.Utilities.CandidatesInfo.CurrentList);
    CandidatesList.ChoiceMode = ChoiceMode.Multiple;
    CandidatesList.Adapter = cva;

适配器:

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;
}

视图:

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
    }
}

复选框.checked在View Monodroid中不起作用

您可以尝试以下方法:

lv.SetItemChecked(1, true);

摘自xamarin官方网站,查看2.2节