-2
簡單的問題對於C#新手C#如果計數器如何更改按鈕「功能」,按它
using Android.App;
using Android.Widget;
using Android.OS;
namespace Sukkis
{
[Activity(Label = "sukkis", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
string person = "sukkis";
string age = "24";
string place = "hell";
int count = 1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.myButton);
TextView kentta = FindViewById<TextView>(Resource.Id.tiedot);
if (count == 2)
{
button.Click += delegate { kentta.Text = "Info"; };
button.Click += delegate { button.Text = "Click additional info"; };
count--;
}
else
{
button.Click += delegate { kentta.Text = $"Name: {person}\nage: {age}\nPlace: {place} \n \nC# is fun"; };
button.Click += delegate { button.Text = "Hide"; };
count++;
}
}
}
}
如何解決這個功能之後?現在,當我第一次按下按鈕,但它不會在第二次按下後再次運行功能。如何實現,如果正確循環以改變每隔一個按鈕之後的文本?感謝您的回答。
在這種情況下,最好只使用布爾值 –