我知道如何将一个字符串从一个活动传递到另一个活动,但是如何为两个字符串执行此操作" nameString"和" 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);
}
});
答案 0 :(得分:2)
通过这种方式,您可以将字符串从一个活动传递到另一个活动
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");
希望它会对你有所帮助:)。
答案 1 :(得分:1)
类似于你通过第一个字符串的方式你可以通过' n'通过意图的字符串数量。
Intent intent = new Intent(AddLocationActivity.this, MapsActivity.class);
intent.putExtra("address", addressString);
intent.putExtra("string2", string2);
AddLocationActivity.this.startActivity(intent);
答案 2 :(得分:0)
通过:
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("name",nameString);
intent.putExtra("address", addressString);
AddLocationActivity.this.startActivity(intent);
}
});
}
获得:
Intent intent = getIntent();
String address = intent.getStringExtra("name");
String string2 intent.getStringExtra("address");