在dot42中检测onTextChanged事件

时间:2013-11-14 12:47:24

标签: android dot42

我想在我的应用程序中使用ediText字段来响应onTextChange事件,以便在文本更改时调用方法。我使用dot42制作应用程序,但只能找到Java提供的教程。

2 个答案:

答案 0 :(得分:4)

这将是一个最小的实现。我希望它可以帮助你看到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生成。

答案 1 :(得分:1)

在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做一些事情就可以了。

相关问题