Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

EditText.TextChanged error

$
0
0

Hi. I'm making an app and I've encountered a problem with the TextChanged and AfterTextChanged events of EditText views. I start by initializing the Text to a value and then add an eventhandler to TextChanged or AfterTextChanged. The problem happens when i try to write something new in the EditText. If i write a new number the TextChanged event will fire twice, and the first time the Text property of my EditText will contain an empty string, even though the EditText is not empty. Then the event fires against and this time the ET contains what i expect. I've added an if statement to check if it's an empty string, but this is just a temporary fix that won't work because then the user can't change the ET to being empty. This is my code:

EditText editNum= FindViewById<EditText>(Resource.Id.editNum);
editNum.Text = SessionVars.numValue;    //SessionVars is my static data container
editNum.TextChanged += (sender, e) =>
{
    if (editNum.Text != "") //Breakpoint here
    {
        int value;
        if (int.TryParse(editNum.Text, out value))
            SessionVars.numValue = value; 
        else
        {
            Toast.MakeText(this, "Num has to be an int.", ToastLength.Long).Show();
            editNum.Text = SessionVars.numValue;
        }
    }
};

Am i doing something wrong or is it a bug?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>