我的第一个Activity调试会更正位置名称和地址的输出,但是第二个Activity会给我一个空值。有人会帮忙吗?
FirstActivity
mySavedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent next = new Intent(MyDestination.this, MyLocationDetail.class);
Bundle extra = getIntent().getExtras();
String locationName = myList.get(position).getLocation_name();
String address = myList.get(position).getAddress();
extra.putString("extra_location", locationName);
extra.putString("extra_address", address);
Log.d(TAG, "name is " + locationName);
Log.d(TAG, "address is "+ address);
intent.putExtras(extra);
startActivity(next);
}
});
SecondActivity
Bundle b = getIntent().getExtras();
String locationName = b.getString("extra_location");
String address = b.getString("extra_address");
Log.d(TAG, "location "+locationName);
答案 0 :(得分:0)
首先尝试获取意图:
Intent intent = getIntent();
然后:
string location = intent.getStringExtra("extra_location")
答案 1 :(得分:0)
试一试:
String locationName = myList.getItemAtPosition(position).getLocation_name();String address = myList.getItemAtPosition(position).getAddress();