2016-04-07 4 views
1

Von MainActivity.cs zu AnotherActivity.csWie man Daten von editText.text auf eine andere Tätigkeit in Xamarin Android passieren, wenn die Taste

public static string hisname; 
    public static string hername; 
    private Handler mHandler = new Handler(); 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     SetContentView(Resource.Layout.Register1); 
     // Create your application here 
     EditText her = FindViewById<EditText>(Resource.Id.editTextHername); 
     EditText his = FindViewById<EditText>(Resource.Id.editTextUrname); 
     //RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f); 
     //anim.setInterpolator 
     //anim.setRepeatCount(Animation.INFINITE); 
     //anim.Duration(700); 
     //splash.StartAnimation(anim); 


     WindowRotationAnimation q = new WindowRotationAnimation(); 
     Button getStarted = FindViewById<Button>(Resource.Id.myButton); 
     getStarted.Click += delegate 
     { 
      var intent = new Intent(this, typeof(CalculateActivity)); 
      intent.PutExtra("yourname", ""+hisname); 
      intent.PutExtra("GFname", "" + hername); 
      StartActivity(intent); 

     }; 
    } 
} 
+0

Hat Ihr EditExt gibt es in Aktivität A und Sie müssen Daten in Aktivität B? – Sumant

+0

Sie setzen die Variablen 'hisname' und' hername' nicht auf die Werte aus den Feldern 'EditText'. –

Antwort

1

mit folgenden

var herName = her.text; 


vad hisName = his.text; 

und fügen Sie in intent.putextra Methode Versuchen geklickt wird.

0

Passdaten von your_first_activity zu your_next_activity

Intent i = new Intent (Application.Context, typeof(your_next_activity)); 
i.PutExtra ("item", "item_to_pass"); 
StartActivity (i); 

abrufen Datenbündel aus your_first_activity auf your_next_activity

string item = Intent.GetStringExtra("item"); 
bestanden
+0

danke. @Akshay –

+0

Ich mag es auf dumme Fehler hinzuweisen: P ** Happy Coding ** –

1
public static string hisname; 
public static string hername; 
private Handler mHandler = new Handler(); 
protected override void OnCreate(Bundle savedInstanceState) 
{ 
    base.OnCreate(savedInstanceState); 
    SetContentView(Resource.Layout.Register1); 
    // Create your application here 
    EditText her = FindViewById<EditText>(Resource.Id.editTextHername); 
    EditText his = FindViewById<EditText>(Resource.Id.editTextUrname); 
    //RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f); 
    //anim.setInterpolator 
    //anim.setRepeatCount(Animation.INFINITE); 
    //anim.Duration(700); 
    //splash.StartAnimation(anim); 


    WindowRotationAnimation q = new WindowRotationAnimation(); 
    Button getStarted = FindViewById<Button>(Resource.Id.myButton); 
    getStarted.Click += delegate 
    { 
     hisname=his.Text; 
     hername=her.Text; 
     var intent = new Intent(this, typeof(CalculateActivity)); 
     intent.PutExtra("yourname", hisname); 
     intent.PutExtra("GFname", hername); 
     StartActivity(intent); 

    }; 
} 

in Ihrem OnCreate des AnotherActivity.cs Sie diese Zeichenfolgen wie diese bekommen können :

string hisname=Intent.GetStringExtra ("yourname"); 
string hername=Intent.GetStringExtra ("GFname"); // Seriously :P 

Dies ist eigentlich eine einfache Lösung, wenn Sie diese wollten. Ich würde vorschlagen, sollten Sie zuerst erforschen, bevor Sie Fragen stellen

Glücklich Coding

Verwandte Themen