我的按钮onClick进程在Xamarin Android中不起作用

问题描述 投票:0回答:1

我的其他buttons正在工作,而这个button只是不起作用。

这是我的代码片段:

 public class RegisterActivity : Activity
{
    EditText txtfullname;
    EditText txtaddress;
    EditText txtusername;
    EditText txtpassword;
    EditText txtconfirmpass;
    Button btncreate;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.registerPage);

        txtfullname = FindViewById<EditText>(Resource.Id.editTextFullname);
        txtaddress = FindViewById<EditText>(Resource.Id.editTextAddress);
        txtusername = FindViewById<EditText>(Resource.Id.editTextUsername);
        txtpassword = FindViewById<EditText>(Resource.Id.editTextPassword);
        txtconfirmpass = FindViewById<EditText>(Resource.Id.editTextConfirmPassword);
        btncreate = FindViewById<Button>(Resource.Id.buttonRegister);

        btncreate.Click += Btncreate_Click; //this doesn't get process even though I have an onclick of it

    }
android xamarin xamarin.android
1个回答
1
投票

首先确保Resource.Id.buttonRegister是你的按钮ID

第二,你创造了EventHandler

btncreate = FindViewById<Button>(Resource.Id.buttonRegister);
btncreate.Click += Btncreate_Click;

private void Btncreate_Click(object sender, EventArgs e)
  {
     //do something when click the button
  }
© www.soinside.com 2019 - 2024. All rights reserved.