简体   繁体   中英

How to check a CheckBox programmatically using Android C#?

How to check a CheckBox programmatically using Android C#? I can't find any solution for this, there are only Java examples of this.

I tried to use SetChecked but that function doesn't exists.

void btnChangeCB_Click(object sender, EventArgs e){
if (cb1.Checked == true) {
    cb1.Toggle ();
  }

Anyway I can toggle the checkboxes, but I can't check them :(.

Simply assign true to the Checked property:

cb1.Checked = true; // Check the checkbox.

In Java properties don't exist. They use Get/Set method pairs. Xamarin condensed them into a property:

In Java:

public bool GetChecked();
public void SetChecked(bool value);

In C#:

public bool Checked { get; set; }

For checking the CheckBox

checkBox1.Checked = true;

For Unchecking the CheckBox

checkBox1.Checked = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM