我在C#中有以下Android应用程序代码
using Android.App;
using Android.Widget;
using Android.OS;
namespace Practicum1
{
[Activity(Label = "Practicum 1.2.1", MainLauncher = true)]
public class MainActivity : Activity
{
EditText invullen;
TextView displaynaam;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
TextView begintekst;
begintekst = new TextView(this);
begintekst.Text = "Vul je naam in!";
invullen = new EditText(this);
invullen.TextChanged += naam_textChanged;
displaynaam = new TextView(this);
displaynaam.Text = "Hier kom je naam te staan";
LinearLayout stapel;
stapel = new LinearLayout(this);
stapel.Orientation = Orientation.Vertical;
stapel.AddView(begintekst);
stapel.AddView(invullen);
stapel.AddView(displaynaam);
// Set our view from the "main" layout resource
this.SetContentView(stapel);
}
private void naam_textChanged(object sender, ItemEventArgs ea)
{
displaynaam.Text = "Welkom " + invullen.Text;
}
}
}
但后来我收到以下错误消息: ' naam_textChanged没有重载匹配委托EventHandler
有谁知道如何解决这个问题?
此致 净莲
答案 0 :(得分:0)
您的事件参数不正确。它看起来应该是这样的。
private void naam_TextChanged (object sender, TextChangedEventArgs e)
{
}
检查EditText
的文档第4点)实施TextChanged
事件以捕获EditText
中的文字并将其写入TextView
。
editText.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
textView.Text = e.Text.ToString ();
};