以下代碼來自我的Android Mono應用程序的C#部分。它將最終成爲萬用表模擬器的GUI,但現在只是顯示文本。這是相當直接的:使用代表的Android Mono中的按鈕屏幕更改
- 點擊其中一個按鈕去那個儀表(電壓表,電流表,歐姆表) - 點擊「重新掃描」按鈕和TextView告訴你多少次你點擊那個按鈕。 - 點擊其中一個米按鈕或主頁按鈕來切換視圖
這麼多工作完美無缺。不幸的是,一旦我切換視圖,按鈕停止工作。以下是歐姆按鈕和Amp按鈕的代碼。歐姆按鈕是「完整的」按鈕,可以顯示所有其他屏幕的視圖。出於測試目的,我正在進入功放屏幕,但是當我去那裏時,其重新掃描按鈕什麼都不做。沒有任何按鈕可以做任何事情。
我相當肯定的是,問題是我使用委託的命令,但沒有我的研究使我在向解決方案的任何方式。
如果需要,我可以提供更多的主代碼和XML代碼。
ampButton.Click += delegate
{
SetContentView(Resource.Layout.AmpScreen);
Button ampButtonData = FindViewById<Button>(Resource.Id.CurrentButtonamp);
TextView ampData = FindViewById<TextView>(Resource.Id.ampdata);
ampButtonData.Click += delegate
{
ampData.Text = string.Format("{0} clicks!", count2++);
};
Button amp2volt = FindViewById<Button>(Resource.Id.Amp2VoltButton);
Button amp2ohm = FindViewById<Button>(Resource.Id.Amp2OhmButton);
Button amp2home = FindViewById<Button>(Resource.Id.Amp2HomeButton);
};
ohmButton.Click += delegate
{
SetContentView(Resource.Layout.OhmScreen);
Button ohmButtonData = FindViewById<Button>(Resource.Id.CurrentButtonohm);
TextView ohmData = FindViewById<TextView>(Resource.Id.ohmdata);
ohmButtonData.Click += delegate
{
ohmData.Text = string.Format("{0} clicks!", count3++);
};
Button ohm2amp = FindViewById<Button>(Resource.Id.Ohm2AmpButton);
Button ohm2volt = FindViewById<Button>(Resource.Id.Ohm2VoltButton);
Button ohm2home = FindViewById<Button>(Resource.Id.Ohm2HomeButton);
ohm2amp.Click += delegate
{
SetContentView(Resource.Layout.AmpScreen);
};
ohm2volt.Click += delegate
{
SetContentView(Resource.Layout.VoltScreen);
};
ohm2home.Click += delegate
{
SetContentView(Resource.Layout.Main);
};
};
非常感謝您斯圖爾特。 我提出了您的建議更改並實施了一些試驗性測試,並對他們的成功感到高興。我的整個GUI現在已經完成,完成了整個結構。 – Zach 2012-03-29 15:52:56