2016-04-07 291 views
1

當從MainActivity.csAnotherActivity.cs按鈕被點擊

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

貴editext有在活動A,你需要在活動B數據之前? – Sumant

+0

您並未將'hisname'和'hername'變量設置爲EditText字段中的值。 –

回答

1

如何從editText.text數據傳遞到另一個活動Xamarin的Android與以下

var herName = her.text; 


vad hisName = his.text; 

嘗試,並加入到intent.putextra方法。從your_first_activity到your_next_activity

0

通數據

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

檢索your_first_activity傳遞your_next_activity

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

謝謝。 @Akshay –

+0

我想指出一些愚蠢的錯誤:P **快樂編碼** –

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); 

    }; 
} 

您的AnotherActivity.cs你的OnCreate內部的數據包可以得到這些字符串這樣:

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

這實際上是一個簡單的解決方案,如果你想要這個。我建議你應該先研究你張貼問題

編碼快樂