Search code examples
androidosmdroid

How do I set values to view in MarkerInfoWindow?


I use the OSMBonusPack library for creating markers on map. From this library, I use MarkerInfoWindow. I extended my own class CustomInfoWindow from MarkerInfoWindow. Then I try to set values for view-elements (tvDescribe and bubbleImage), that is contained in the layout of the InfoWindow, but a NullPointerException from it appears:

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);
    }
}

What am I doing wrong?


Solution

  • Maybe you should be use onOpen() method:

        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);
        }