0

我是 android 单声道的新手。我正在尝试制作一个简单的复选框列表,我可以在其中选择我的候选人,按下按钮将它们插入数据库。到这里为止一切都很好,但问题在于加载我的检查值。即使我明确地放了 this.Checked = true;我的复选框也总是未选中

这是我的代码:

加载列表视图:

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

1 回答 1

0

您可以尝试这种方法:

lv.SetItemChecked(1, true);

取自官方 xamarin 网站并查看第 2.2 节

于 2013-06-17T07:12:51.697 回答