我希望我的应用程序中有一个ediText字段来响应onTextChange事件,所以当文本发生变化时会调用一个方法。我正在使用dot42来制作这个应用程序,但是只能找到用Java提供的教程。
发布于 2013-11-14 14:14:50
这将是一个最低限度的实现。我希望它能帮助您了解Java和C#之间的差异--这确实是微不足道的。
[Activity]
public class MainActivity : Activity, Android.Text.ITextWatcher
{
protected override void OnCreate(Bundle savedInstance)
{
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
EditText editText = FindViewById<EditText>(R.Ids.status);
editText.AddTextChangedListener(this);
}
public void AfterTextChanged(Android.Text.IEditable s)
{
throw new NotImplementedException();
}
public void BeforeTextChanged(Java.Lang.ICharSequence s, int start, int count, int after)
{
throw new NotImplementedException();
}
public void OnTextChanged(Java.Lang.ICharSequence s, int start, int before, int count)
{
throw new NotImplementedException();
}
}接口实现由Visual生成。
发布于 2013-11-14 13:03:48
在Java中,您可以通过实现TextWatcher接口来实现它。Dot42文档说
AddTextChangedListener(ITextWatcher watcher)
Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.` 所以,实现ITextWatcher,在AfterTextChanged中做一些事情,你就没事了。
https://stackoverflow.com/questions/19978048
复制相似问题