无法从其他活动获取字符串数据

时间:2016-05-16 14:29:53

标签: java android

我从次要活动中获得了字符串数据。然后我想更改主要活动上的标记标题,但它无法读取。 这是数据:

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode,resultCode, data);
    if(requestCode == 22 && resultCode == RESULT_OK){
        View view = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getView();
        addButton.setText(data.getStringExtra("Nama"));
        String nama = (data.getStringExtra("Nama"));


    }

可以为addButton读取数据,但我们无法为String nama

获取数据

这是我的按钮:

addButton = (Button)findViewById(R.id.addButton);

这是我的标记

private class RadiusCircle {

    private final Marker centerMarker;

    private final Circle circle;

    private double radius;

    public RadiusCircle(LatLng center, double radius) {
        this.radius = radius;
        centerMarker = mMap.addMarker(new MarkerOptions()
                .position(center)
                .title(nama)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.bulet))
                .draggable(false));

        circle = mMap.addCircle(new CircleOptions()
                .center(center)
                .radius(radius)
                .strokeWidth(2)
                .strokeColor(mStrokeColor)
                .fillColor(mFillColor));
    }



    public void onStyleChange() {
        circle.setStrokeWidth(2);
        circle.setFillColor(mFillColor);
        circle.setStrokeColor(mStrokeColor);
    }
}

标题.title(nama)无法获得,我可以得到一些帮助吗?谢谢你的好意

1 个答案:

答案 0 :(得分:0)

public class MainActivity extends Activity
{
String nama;
.....
..... 

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode, data);
if(requestCode == 22 && resultCode == RESULT_OK){
    View view = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
            .getView();
    addButton.setText(data.getStringExtra("Nama"));
    nama = (data.getStringExtra("Nama"));

.....

}