I want to have a button which can show a different toast message depend on the user's click times. The code I write as below. However, after I click, all four toast message pop up. Can anyone help me fix this? THX!
GetVS.Click += delegate {
if(count==0)
{
Toast.MakeText (this, "Beep Boop0", ToastLength.Short).Show ();
}
if(count==1)
{
Toast.MakeText (this, "Beep Boop1", ToastLength.Short).Show ();
}
if(count==2)
{
Toast.MakeText (this, "Beep Boop2", ToastLength.Short).Show ();
}
else
{
Toast.MakeText (this, "Beep Boop else", ToastLength.Short).Show ();
}
count++;
};
Toast.makeText(..)
returns a new Instance of Toast, you can create one outside the delegate and then call myToast.setText
to change the text and then call Show
to display it.
You are creating 4 instance using Toast.makeText(..)
, and not changing the text.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.