I’m having an issue accessing a checkbox inside a ListView.
I’m trying to set the checkbox on creation of each View.
I made a custom adapter implementing this function:
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
view = context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItemChecked, null);
view.FindViewById<TextView>(Android.Resource.Id.Text1).Text = items[position]._fName + items[position]._lName;
// This seems to return null.. I'm probably accessing it the wrong way.
view.FindViewById<CheckBox>(Android.Resource.Id.Checkbox).Checked = items[position]._Enabled;
return view;
}
Problem is that, as the comment state, the program throws a System.NullReferenceException.
Point is that I have no clue how to access the checkbox otherwise.
Any help is apreciated.
I don’t know if this is the best way to proceed, yet it worked for me:
Considering we know the list will consist of a text and a checkbox, I casted straight to a CheckedTextView..
It might not be the right/best way to achieve this but at least it works..