通过活动,从C#的输入值 [英] pass input value from activities c#

查看:120
本文介绍了通过活动,从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.

https://www.dropbox.com/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#的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆