如何设置要在MarkerInfoWindow中查看的值?

时间:2016-01-21 18:38:48

标签: android osmdroid

我使用OSMBonusPack库在地图上创建标记。在这个库中,我使用MarkerInfoWindow。我从CustomInfoWindow扩展了自己的课程MarkerInfoWindow。然后,我尝试为tvDescribe的布局中包含的视图元素(bubbleImageInfoWindow)设置值,但会显示NullPointerException:< / p>

public class CustomInfoWindow extends MarkerInfoWindow {
    TextView tvDescribe; //Description of point in infoWindow
    ImageView bubbleImage;//Image in infoWindow
    View view;

public CustomInfoWindow(MapView mapView, Drawable markerImage, String description) {
            super(R.layout.my_layout, mapView);//my_layout is layout for InfoWindow
            view = mapView;
            tvDescribe = (TextView)view.findViewById(R.id.bubble_description);
            bubbleImage = (ImageView)view.findViewById(R.id.bubble_image);
            tvDescribe.setText(description);
            bubbleImage.setImageDrawable(markerImage);
    }
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

也许您应该使用 onOpen()方法:

    TextView tvDescribe; //Description of point in infoWindow
    ImageView bubbleImage;//Image in infoWindow

    Drawable markerImage;
    String description;


    public CustomInfoWindow(MapView mapView, Drawable markerImage, String description) {
        super(R.layout.my_layout, mapView);//my_layout is layout for InfoWindow

        this.markerImage = markerImage;
        this.description = description;

    }

    @Override
    public void onOpen(Object item) {
        super.onOpen(item);

        tvDescribe = (TextView)getView().findViewById(R.id.bubble_description);
        bubbleImage = (ImageView)getView().findViewById(R.id.bubble_image);
        tvDescribe.setText(description);
        bubbleImage.setImageDrawable(markerImage);
    }