More than one * Layout * in the app

1

How do I instantiate a new screen, I have the Main.axml and wanted it when I clicked the button to call my Result.axml . I would like to know how I do this in Xamarin in C #. What if I need 2 Activity's one for each screen.

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

    
asked by anonymous 02.08.2014 / 23:39

2 answers

3

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

Notice that each axml has a Activity in this example and would be the simplest way to achieve what you need. I would have to make everything respond in the same Activity but I think 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);
            };

        }

    }
}

Second 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";

        }
    }
}
    
04.08.2014 / 14:48
0

Try to do this

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

For more questions, the xamarim website has the first steps
link

    
22.09.2015 / 01:18