将值传递给另一个活动 [英] passing values to another activity

查看:134
本文介绍了将值传递给另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以字符串格式传递价值0000002到下一个活动象下面这样:

I am trying to pass value "0000002" in string format to next activity like below:

Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras("EmpID", "0000002");

在第二个活动

Bundle info = getIntent().getExtras();
System.out.println("Test " + info.getString("EmpID")); // this line printing "null" value instead of "0000002". 

我能顺利通过并成功获取其他字符串。我不能够获取的EmpID。

I am able to pass and fetch the other strings successfully. I am not able to fetch the EmpID.

请帮我。

推荐答案

下面是一个简单的

从3月1活动

Bundle localBundle = new Bundle();
localBundle.putString("Loan Amount", editText1.getText().toString());
localBundle.putString("Loan Tenture", editText2.getText().toString());
localBundle.putString("Interest Rate", editText3.getText().toString());
Intent localIntent = new Intent(this, Activity2.class);
localIntent.putExtras(localBundle);
startActivity(localIntent);

和活性2

String string1 = getIntent().getStringExtra("Loan Amount");
String string2 = getIntent().getStringExtra("Loan Tenture");
String string3 = getIntent().getStringExtra("Interest Rate");

有关你的情况,你可以使用像

For your case, you can use like

Bundle localBundle = new Bundle();
localBundle.putString("EmpID", "0000002");
Intent pass = new Intent(this, SecondActivity.class);
pass.putExtras(localBundle);
startActivity(pass);

在SecondActivity你可以得到EMPID像

and in SecondActivity you can get the EmpId like

String empId = getIntent().getStringExtra("EmpID");


-----------------的的另一种思路 ----------- ------


----------------- Another Way -----------------

Intent pass = new Intent(this, SecondActivity.class);
pass.putExtra("EmpID", "0000002");
startActivity(pass);

在第二个活动,你可以得到EMPID像

In second activity you can get the EmpId like

Bundle bundle = getIntent().getExtras();
String empId = bundle.getString("EmpID"); 

这篇关于将值传递给另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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