I am trying to implement an interface that will listen on my EditText when user types a single character on it such that when that happens I will get a Toast message that You tried to type a new character and when user clears then this interface will check the length of the characters inside the EditText and display a Toast message that you cleared all the text if the count is 0. This is where the Android.Text.IWatcher interface comes in. I have implemented it in my main class like this...
public class MainActivity : AppCompatActivity,ITextWatcher
{
//after I implemented the interface then these methods were generated by the compiler
public void OnTextChanged(Java.Lang.ICharSequence s, int start, int before, int count)
{
//check the length of characters typed and show a Toast
if (s.Length() > 0)
{
Toast.MakeText(this, "You are typing more text", ToastLength.Long).Show();
}
//if user clears all text also show a Toast
if (s.Length() == 0)
{
Toast.MakeText(this, "You have cleared all the text", ToastLength.Long).Show();
}
}
}
I assigned the Interface to my EditText like below.
EditText user_message = chat_view.FindViewById<EditText>(Resource.Id.message_box);
//assign a text watcher to the EditText
user_message.AddTextChangedListener(this);
The problem is that I do not get the Toasts when I type in my EditText when i debug this application to my android device, help me resolve this, Thank You.