Search code examples
androiddot42

Detecting an onTextChanged event in dot42


I want an ediText field in my app to respond to onTextChange events so a method is called when the text changes. I am using dot42 to make the app but could only find tutorials available in Java.


Solution

  • This would be a minimal implementation. I hope it helps you see a pattern in the difference between Java and C# - it is really trivial.

       [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();
          }
       }
    

    The interface implementation is generated by Visual Studio.