繁体   English   中英

如何使程序循环到顶部?

[英]How can I get the program to loop to the top?

好的,我是Android和C#的新手。 其实今天才刚开始。 我通常使用VB进行编程,但是无论如何我都尝试使用MonoDroid,并且在进行了一些小型教程之后,我自己尝试了一些方法。 我想要的是在画布上有两个单选按钮。 还有一个禁用的按钮,仅当您单击其中一个单选按钮时才会启用。 有趣的是,您必须对单选按钮进行编码,以取消选中与Windows窗体不同的单击其他窗体的时间,或者我遗漏了一些东西。 但是我做到了。 然后,当您按下“下一步”按钮时,它将转到下一页。

这是我上面的代码:

    protected override void OnCreate(Bundle bundle)
    {

        base.OnCreate(bundle);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        RadioButton radSilent1 = FindViewById<RadioButton>(Resource.Id.radSilent);
        RadioButton radVibrate1 = FindViewById<RadioButton>(Resource.Id.radVibrate);
        Button button1 = FindViewById<Button>(Resource.Id.btnNext);
        radSilent1.Click += delegate
        {
            button1.Enabled = true;
            if (radSilent1.Checked == true)
                radVibrate1.Checked = false;
            else if (radVibrate1.Checked == true)
                radSilent1.Checked = false;
            {
            }
        };
        radVibrate1.Click += delegate
        {
            button1.Enabled = true;
            if (radVibrate1.Checked == true)
                radSilent1.Checked = false;
            else if (radSilent1.Checked == true)
                radVibrate1.Checked = false;
            {
            }
        };
        // Set our view from the "secondry" layout resource
        button1.Click += delegate { SetContentView(Resource.Layout.Secondry); };
    }

这将弹出第二个画布。 我还有另一个按钮“返回”。 当我按下该按钮时,它带我到第一个屏幕,但是上面的代码不起作用。 我按下了两个单选按钮,并且两个按钮均已选中,并且该按钮均未启用。 为什么会这样? 记住我很抱歉。 大声笑任何帮助是非常感谢。

谢谢。

错误是,当您使用新的布局( SetContentView(Resource.Layout.Secondry) )时,您丢失了所有在OnCreate(Bundle bundle)初始化的附加事件处理程序。 要解决此问题,您需要创建2种方法,如InitializeMainView()InitializeSecondView() ,在其中将处理程序附加到控件以控制选定布局上的事件。 更改布局后,您只需为选定的视图调用init方法。

但是我认为最好的解决方案是为第二个视图创建新的单独活动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM