本文介绍了通过活动,从C#的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用户输入的文本从传递到活动1活性2。我试过的东西很多,但所有的对我做了这个错误的东西,这是错误当我试图把在TextView的价值我得到。
I'm trying to pass user input text from activity1 to activity2. I tried alot of thing but all of the thing did to me this error, this is the error i get when i'm trying to put the value in textview.
www.dropbox/s/cpsbflk4r1ep46x/error.PNG
//this is the first activity SetContentView(Resource.Layout.Main); base.OnCreate(bundle); TextView t1 = FindViewById<TextView>(Resource.Id.t1); long l = 1; ImageButton i1 = FindViewById<ImageButton>(Resource.Id.i1); i1.Click += delegate { t1.Text = l++.ToString(); }; Button b1 = FindViewById<Button>(Resource.Id.b1); b1.Click += (sender, e) => { string b = t1.Text; Intent intent = new Intent(this, typeof(Activity2)); intent.PutExtra("j", b); StartActivity(intent); }; //this is the second activity TextView money = FindViewById<TextView>(Resource.Id.money); SetContentView(Resource.Layout.layout1); var l = this.Intent.Extras.GetString("j"); money.Text = l;感谢,
推荐答案试试这个:
在主要活动
var activity2 = new Intent (this, typeof(next_activity)); activity2.PutExtra ("value",i); StartActivity (activity2);在next_activity
On the next_activity
var Passed_value = Intent.GetStringExtra ("value",0); // for int use: Intent.GetIntExtra也可以尝试改变
t1.Text = l++.ToString();到
t1.Text = l++;和
string b = t1.Text;到
string b = t1.Text.ToString();更多推荐
通过活动,从C#的输入值
发布评论