通过活动,从C#的输入值

编程入门 行业动态 更新时间:2024-10-28 19:35:56
本文介绍了通过活动,从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#的输入值

本文发布于:2023-11-11 04:45:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577414.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!