Search code examples
androidxamarin.androidxamppdisabled-inputtabstop

how i makes decrement value stop at zero


I am a beginner in xamarin android and I try to develop a simple app in xamarin android that makes decrement value into zero only ... but when I am trying the decrement value is continue to the negative value I cant makes it stop at zero value

how I can make decrement value stop at zero?

enter code here   public class MainActivity : AppCompatActivity
{
    int txt3;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        TextView textView1 = FindViewById<TextView>(Resource.Id.textView1); 
        txt3 = 5;
        textView1.Click += delegate
        {
            textView1.Text = (txt3--).ToString();

        };
    }
}

}

when I run the app the value are 5 4 3 2 1 0 -1 -2 -3 ...etc


Solution

  •   textView1.Click += delegate
    {
        result = text3--;
        if (result < 0) {
            result = 0;
        }
        textView1.Text = (result).ToString();
    };