我有一个活动叫 GatherActivity
其中我有 EditText
. 用户可以输入任何他想要的东西。现在我需要输入的是 EditText
在另一个班级,称为 MapActivity
.我创建了一个 Intent
来 "把它放在 "另一个活动中。objecteditText总是一个空对象,所以没有任何东西显示为markerSnippet.这里是我的代码(GahterActivity)在onButtonClick()方法中。
public void onButtonClick(View view){
EditText editText_markerSnippet = (EditText) findViewById(R.id.editText_markerSnippet);
Intent intent = new Intent(this, MapActivity.class);
intent.putExtra("markerSnippet", editText_markerSnippet.getText().toString());
}
在MapActivity中的代码,在我的markerSnippet中,有一个方法onButtonClick():
Bundle extras = getIntent().getExtras();
if(extras != null){
markerSnippet = extras.getParcelable("markerSnippet");
}else{
markerSnippet = "some extra info about your location"
}
在我的marker snippet中没有文本,所以这里没有使用else case... ...
你正在发送一个 String
但期待一个 Parcelable
在你的活动中。
在你的 MapActivity
,改成。
markerSnippet = extras.getString("markerSnippet");