首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在单击按钮时将数据从editText.text传递到Xamarin Android中的另一个活动

如何在单击按钮时将数据从editText.text传递到Xamarin Android中的另一个活动
EN

Stack Overflow用户
提问于 2016-04-07 17:08:35
回答 3查看 1K关注 0票数 1

MainActivity.csAnotherActivity.cs

代码语言:javascript
复制
  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);

        };
    }
}
EN

回答 3

Stack Overflow用户

发布于 2016-04-07 17:58:18

尝试使用以下命令

代码语言:javascript
复制
var herName = her.text;


vad hisName = his.text;

并添加到intent.putextra方法中。

票数 1
EN

Stack Overflow用户

发布于 2016-04-07 18:24:49

代码语言:javascript
复制
  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中,您可以获得如下字符串:

代码语言:javascript
复制
string hisname=Intent.GetStringExtra ("yourname");
string hername=Intent.GetStringExtra ("GFname"); // Seriously :P

如果你想要这个,这实际上是一个简单的解决方案。我建议你在发表问题之前先研究一下。

快乐编码

票数 1
EN

Stack Overflow用户

发布于 2016-04-07 18:16:53

将数据从your_first_activity传递到your_next_activity

代码语言:javascript
复制
Intent i = new Intent (Application.Context, typeof(your_next_activity));
i.PutExtra ("item", "item_to_pass");
StartActivity (i);

检索从your_next_activity上的your_first_activity传递的数据包

代码语言:javascript
复制
string item = Intent.GetStringExtra("item");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36471535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档