【发布时间】:2012-03-28 22:05:19
【问题描述】:
以下代码来自我的 Android Mono 应用程序的 C# 部分。它最终将成为万用表模拟器的 GUI,但现在只显示文本。这是相当直截了当的:
-单击其中一个按钮以转到该表(电压表、电流表、欧姆表) -单击“重新扫描”按钮,TextView 会告诉您单击该按钮的次数。 - 单击其他仪表按钮之一或主页按钮以切换视图
这么多工作完美无缺。不幸的是,一旦我切换视图,按钮就会停止工作。下面是 Ohm 按钮和 Amp 按钮的代码。 Ohm 按钮是“完整”按钮,可显示所有其他屏幕的视图。出于测试目的,我要去放大器屏幕,但是当我去那里时,它的重新扫描按钮什么也没做。没有一个按钮做任何事情。
我相当确定问题在于我对 delegate 命令的使用,但我的研究都没有以任何方式引导我找到解决方案。
如果需要,我可以提供更多的主要代码和 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);
};
};
【问题讨论】:
标签: c# android visual-studio-2010 mono xamarin.android