Ste*_*hot 1 c# asp.net android xamarin
今天开始使用Visual Studio中的xamarin开发它到目前为止看起来不错但我的问题是
如何从按钮单击切换到另一个布局(视图)
当我在登录页面上执行此操作时,如下所示:
[Activity(Label = "Test", MainLauncher = true, Icon = "@drawable/icon")]
public class Test: Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Afvalwijzer);
        EditText Bla1 = FindViewById<EditText>(Resource.Id.Bla1);
        Bla1.Hint = "Your text";
        EditText Bla2= FindViewById<EditText>(Resource.Id.Bla2);
        Bla2.Hint = "Your text";
        Button Login = FindViewById<Button>(Resource.Id.BtnLogin);
        Login.Click += new EventHandler(Login_Click);
    }
    void Login_Click(object sender, EventArgs e)
    {
        EditText Bla1 = FindViewById<EditText>(Resource.Id.Bla1);
        EditText Bla2 = FindViewById<EditText>(Resource.Id.Bla2 );
        if (!String.IsNullOrEmpty(Bla1.Text) && !String.IsNullOrEmpty(Bla2.Text))
        {
            AfvalwijzerWS WebS = new AfvalwijzerWS();
            var Data = WebS.Authenticate(Bla1.Text, Bla2.Text);
            TextView txt = FindViewById<TextView>(Resource.Id.ContentTextView);
            if (Data.Count() > 0)
            {
                SetContentView(Resource.Layout.Index);
            }
            else
            {
                MessageBox("No Access !");
            }
        }
        else
        {
            MessageBox();
        }
    }
这很好.但当我在索引(布局)上我有相同的代码,如下所示:
 protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Index);
        Button Contact = FindViewById<Button>(Resource.Id.BtnContact);
        Contact.Click += (sender, e) =>
        {
            SetContentView(Resource.Layout.Contact);
        };
    }
并且它在布局ofc的xml中引用但它不会触发按钮事件有人知道为什么吗?
您应该开始一个新活动,而不是设置内容视图
 protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Index);
        Button Contact = FindViewById<Button>(Resource.Id.BtnContact);
        Contact.Click += (sender, e) =>
        {
            StartActivity(new Intent(this, typeof(/* whatever activity you want */ )));
            // e.g.
            //StartActivity(new Intent(this, typeof(SplashActivity)));
        };
    }
| 归档时间: | 
 | 
| 查看次数: | 6008 次 | 
| 最近记录: |