0
Well, I created two Activities when I clicked on the button of the first one it should open the second one with information received from the first one. But that’s not what happens, where I’m wrong?
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
//Atividade Principal
namespace TabelaPeriodica
{
[Activity (Label = "TabelaPeriodica", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
EditText edt = FindViewById<EditText> (Resource.Id.edtsmb);
Button bttn = FindViewById<Button> (Resource.Id.env);
if (!string.IsNullOrEmpty(edt.Text))
{
bttn.Click += delegate {
var ress = new Intent (this, typeof(Result));
ress.PutExtra ("simbol", edt.Text);
StartActivity (ress);
};
}
}
}
}
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 TabelaPeriodica
{
[Activity (Label = "Result")]
public class Result : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Create your application here
SetContentView (Resource.Layout.Result);
TextView sm = FindViewById<TextView> (Resource.Id.tsimb);
sm.Text = Intent.GetStringExtra ("simbol") ?? "Erro";
}
}
}
Log the application to help us. You have declared the second Activity in the application manifest?
– Helder