xamarin android按钮单击不起作用

时间:2017-06-23 06:23:07

标签: c# android xamarin

我是xamarin的新手。所以只是尝试做基本的应用程序。但是按钮点击不起作用,即当没有执行从应用程序代码点击时

MainActivity.cs

StartActivity(typeof(LoginActivity));

LoginActivity.cs

   protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Create your application here
        SetContentView(Resource.Layout.Login);

        Button button = FindViewById<Button>(Resource.Id.loginButton);
        if (button != null)
        {
            button.Click += (sender, e) =>
            {
                save();
            };
        }
    }
    public void save()
    {
        string ab = "asbs";
        Console.WriteLine("Working");
    }

2 个答案:

答案 0 :(得分:1)

声明以下方法:

public void save(Object sender, System.EventArgs e)
{
    // Add code to run when the button is clicked here

}

要将方法附加到click事件,请在代码中包含以下内容:

if (BtnSave != null)
{
    BtnSave.Click += save;

}

答案 1 :(得分:0)

试试这个

// set onclick listener here, by deleting some process
    button.Click += delegate {
        loginButtonClick();
    };

public void loginButtonClick()
{
    Toast.MakeText(this, "Proceed to Login ", ToastLength.Long).Show();
}