本週我一直在學習C#,並即時創建一個應用程序。我試過goto聲明,但是lebels是「超出範圍」我希望它把我送回到原始佈局,我發現我需要回到代碼的頂部。 thx提前。Android C#xamarin幫助!需要按鈕帶我回到代碼頂部
namespace TheAppOfJack
{
[Activity(Label = "The App Of Jack", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button1 = FindViewById<Button>(Resource.Id.MyButton);
button1.Click += delegate { button1.Text = string.Format("You have clicked this random button {0} times (͡° ͜ʖ ͡°)", count++); };
Button button2 = FindViewById<Button>(Resource.Id.button1);
button2.Click += delegate
{
SetContentView(Resource.Layout.Gallery);
Button button3 = FindViewById<Button>(Resource.Id.back);
button3.Click += delegate { SetContentView(Resource.Layout.Main); };
Button button4 = FindViewById<Button>(Resource.Id.next1);
button4.Click += delegate
{
SetContentView(Resource.Layout.Gallery2);
button3.Click += delegate { SetContentView(Resource.Layout.Main); };
Button button5 = FindViewById<Button>(Resource.Id.next2);
button5.Click += delegate
{
SetContentView(Resource.Layout.Gallery3);
Button button6 = FindViewById<Button>(Resource.Id.home);
button6.Click += delegate {
//this is where i want the code to send me back to the top };
};
};
};
}
}
}
你想完成什麼? (也就是說爲什麼你要回到頂端?)一個'for'循環會做你需要的嗎? –
我需要到達代碼的頂部,因爲如果我只是將其設置回郵件佈局,則沒有任何的代碼可以工作。如果這可以通過一個for循環來解決,你可以把它放到我的代碼中,因爲我從未使用它們,也不知道從哪裏開始。 thx –
我認爲你所要做的與Android體系結構非常相反。我認爲你應該找到與你想要做的和研究相似的樣本項目。 –