More than one *Layout* in the app

Asked

Viewed 1,193 times

1

How do I instantiate a new screen, I have the Main.axml And I wish that when I hit the button I’d call my own Result.axml. I wonder how I do it in Xamarin in C#. And if I need 2 Activities’s one for each screen.

I also need to pass values from my first activity to my secondary (layout) activity.. how do I do this with c# (Xamarin studio)?

  • PF people tell me how I do to call a new activity(screen) on Xamarin

2 answers

3

You must create a Intent and call StartActivity with this Intent. To pass the parameters, use the extras which act as a value key to store the parameters.

Note that each axml has a Activity in this example and it would be the simplest way to achieve what you need. It would have how to make everything respond in the same Activity but I believe that the solution would be more complex to understand.

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace PrimeiraAtividade
{
    [Activity (Label = "PrimeiraAtividade", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {


        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.LayoutUm);

            bttn.Click += delegate {
                var activity2 = new Intent (this, typeof(Result));
                activity2.PutExtra ("parametro1", edt.Text);
                StartActivity (ractivity2ess);
            };

        }

    }
}

Segunda Activity:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace SegundaAtividade
{
    [Activity (Label = "SegundaAtividade")]         
    public class Result : Activity
    {

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Create your application here
            SetContentView (Resource.Layout.LayoutDois);

            TextView sm = FindViewById<TextView> (Resource.Id.meu_texto);

            sm.Text = Intent.GetStringExtra ("parametro2") ?? "Erro";

        }
    }
}

0

Try to do that

var intent = new Intent(this, typeof(layoutDois));
    intent.PutStringArrayListExtra("Lista", Lista);
    StartActivity(intent);

For more questions the site of the shaman has the first steps
https://developer.xamarin.com/guides

Browser other questions tagged

You are not signed in. Login or sign up in order to post.