如何在Android中将两个字符串从一个活动传递到另一个活动 [英] How to pass two Strings from one Activity to another Activity in Android
本文介绍了如何在Android中将两个字符串从一个活动传递到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何将一个字符串从一项活动传递到另一项活动,但是您如何对两个字符串"nameString"和"addressString"执行此操作?
I know how to pass one string from one activity to another, but how would you do this for two strings "nameString" and "addressString"?
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addressString = address.getText().toString();
nameString = name.getText().toString();
Intent intent = new Intent(AddLocationActivity.this, MapsActivity.class);
intent.putExtra("address", addressString);
AddLocationActivity.this.startActivity(intent);
}
});
推荐答案
通过这种方式,您可以将字符串从一个活动传递到另一个活动
this way you can pass and retrive string from one activity to another activity
Intent intent = new Intent(AddLocationActivity.this, MapsActivity.class);
intent.putExtra("address", addressString);
intent.putExtra("string2", string2);
startActivity(intent);
将字符串检索到 MapsActivity
Intent intent = getIntent();
String address = intent.getStringExtra("address");
String string2 intent.getStringExtra("string2");
希望它会对您有所帮助:)
Hope it will help you :)
这篇关于如何在Android中将两个字符串从一个活动传递到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文