【发布时间】:2013-11-14 12:47:23
【问题描述】:
我希望我的应用程序中有一个 ediText 字段来响应 onTextChange 事件,以便在文本更改时调用一个方法。我正在使用 dot42 制作应用程序,但只能找到 Java 中的教程。
【问题讨论】:
我希望我的应用程序中有一个 ediText 字段来响应 onTextChange 事件,以便在文本更改时调用一个方法。我正在使用 dot42 制作应用程序,但只能找到 Java 中的教程。
【问题讨论】:
这将是一个最小的实现。我希望它可以帮助您了解 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 Studio 生成。
【讨论】:
在 Java 中,您可以通过实现 TextWatcher 接口来实现。 Dot42 documentation 这么说
AddTextChangedListener(ITextWatcher watcher)
Adds a TextWatcher to the list of those whose methods are called whenever this TextView's text changes.`
所以实现ITextWatcher,在AfterTextChanged 中做点什么就可以了。
【讨论】: