【问题标题】:What is wrong with my intent.putExtras (Cannot resolve string)?我的 intent.putExtras 有什么问题(无法解析字符串)?
【发布时间】:2016-04-27 06:34:49
【问题描述】:

我需要获取地址并将其传递给谷歌地图。我已将所有数据传递给 DisplayItem Activity。现在,从 Displayitem 活动中,我只想将地址传递给 MapActivity。

这是我成功显示所有数据的活动。之后,我创建了一个按钮,以便用户可以转到 mapActivity 来查看位置。

private Bundle extras;

private TextView mallAddress;
private TextView tvMallName;
private TextView state, url, phone_number, mail,wb,pn, town;

ImageView map_Locations;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_displayitem);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    tvMallName = (TextView) findViewById(R.id.tv_mallname);
    state = (TextView) findViewById(R.id.states);
    mallAddress = (TextView) findViewById(R.id.mall_Address);

    map_Locations= (ImageView) findViewById(R.id.map_location);



    extras = getIntent().getExtras();
    String malladress = extras.getString(EXTRA_ADDRESS,"");
    String mallName = extras.getString(EXTRA_NAME, "");
    String mallstate = extras.getString(EXTRA_STATE,"");


    mallAddress.setText(malladress);
    tvMallName.setText(mallName);
    state.setText(mallstate);

}

这是我创建的按钮(我的字符串“地址”有问题)我做错了吗?它在 intent.putExtras() 处显示(无法解析字符串,字符串)

public void map(View view){
    map_Locations= (ImageView) findViewById(R.id.map_location);
    map_Locations.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String address = mallAddress.getText().toString();
            Intent intent= new Intent(Displayitem.this, MapsActivity.class);

            intent.putExtras(MapsActivity.EXTRA_ADDRESS, address);
            startActivity(intent);


        }
    });

}

在 MapActivity 我检索数据

 private void getAddress(GoogleMap googleMap)  {

   try {
       mMap = googleMap;
       Intent intent = getIntent();
       extras = intent.getExtras();

       Geocoder geocoder = new Geocoder(this);


       address = extras.getString(this.EXTRA_ADDRESS);

       location = geocoder.getFromLocationName(address, 1);
       if (location.size() > 0) {
           lati =location.get(0).getLatitude();
           lon =location.get(0).getLongitude();
           MarkerOptions options = new MarkerOptions()
                   .title(name)
                   .position (new LatLng(lati, lon));
           mMap.addMarker(options);
       }

   }catch (Exception e){
       e.printStackTrace();

   }
}
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    getAddress(googleMap);
    setUpMap();

}

ps。我是新手

【问题讨论】:

    标签: java android google-maps


    【解决方案1】:

    不是

    intent.putExtras(...);
    

    只是intent.putExtra(...)

    intent.putExtra(MapsActivity.EXTRA_ADDRESS, address);
    

    查看official docs

    【讨论】:

    • 我现在笑得很大声。哈哈哈。我太笨了。 OMG O_O.. 哈哈,你把我叫醒了
    • @Critako 休息一下,恢复精神。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    • 2020-03-22
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多