这是我的初学者问题。 我刚刚介绍了android编程,现在我只是玩一个简单的计算器程序,只是为了看看我如何用我的源代码连接我的xaml文件。所有的程序确实要求两个整数,然后将它们加在一起,如果"等于"按下按钮,将结果显示在空的EditText中。
1)是一个EditText右边的空框来显示结果吗? 2)当按下相等按钮时,如何让EditText显示我的结果?这里是我缺少" if-declaration":
的代码 //output result
if //button result is clicked:
{
res.Text = res.ToString();
}
如果宣言,你可以向我提示吗?
谢谢!
答案 0 :(得分:0)
我建议使用文本框
如果您使用的是Xamarin for Android。首先,您必须找到按钮
获取对通过Android Designer在布局文件中创建的控件的引用。然后在调用SetContentView
之后在OnCreate方法中添加以下代码Button buttonEqual = FindViewById<Button>(Resource.Id.CallButton);
然后添加以下代码以响应按钮单击
buttonEqual.Click += (object sender, EventArgs e) =>
{
// When the button is clicked,
// display the result in the textbox
textBox.Text = res.ToString();
}