是否可以通过单击 axml 的设计来添加按钮单击事件?如果是,那怎么办?如果没有,我该如何通过其他方式添加?我正在尝试使用 Visual Studio 2010 制作我的第一个应用程序。
代码示例
public class Activity1 : Activity
{
string dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "tdsl_validation.sqlite");
private Button login_button;
private EditText user;
private EditText passs;
protected override void OnCreate(Bundle bundle)
{
var ss=dbPath;
base.OnCreate(bundle);
user = (EditText)FindViewById(Resource.Id.editText1);
passs = (EditText)FindViewById(Resource.Id.editText3);
login_button = (Button)FindViewById(Resource.Id.button1);
login_button.Click += new EventHandler(button1_Click);
SetContentView(Resource.Layout.Main);
}
private bool validate_user(string username, string password)
{
bool i;
i = true;
string str;
DataTable dt = new DataTable();
string dbPath1 = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "tdsl_validation.sqlite");
SqliteConnection con = new SqliteConnection("Data Source="+ dbPath1);
str = "select pass from user_detail where user_name='" + username + "' and pass='" + password + "'";
SqliteCommand cmd = new SqliteCommand(str, con);
SqliteDataAdapter da = new SqliteDataAdapter(cmd);
da.Fill(dt);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
i = true;
}
else
{
i = false;
}
}
else
{
i = false;
}
return i;
}
void button1_Click(object sender, EventArgs e)
{
bool i;
user = (EditText)FindViewById(Resource.Id.editText1);
passs = (EditText)FindViewById(Resource.Id.editText3);
i = validate_user(user.Text, passs.Text);
i = validate_user(user.Text, passs.Text);
if (i == true)
{
}
else
{
Toast.MakeText(this, "Invalid Username or Password", ToastLength.Short).Show();
}
// stuff here
}
}