如何设置值以在 MarkerInfoWindow 中查看?
How do I set values to view in MarkerInfoWindow?
我使用 OSMBonusPack 库在地图上创建标记。在这个库中,我使用 MarkerInfoWindow
。我从 MarkerInfoWindow
扩展了自己的 class CustomInfoWindow
。然后我尝试为包含在 InfoWindow
布局中的视图元素(tvDescribe
和 bubbleImage
)设置值,但是它出现了一个 NullPointerException
:
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);
}
}
我做错了什么?
也许你应该使用 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);
}
我使用 OSMBonusPack 库在地图上创建标记。在这个库中,我使用 MarkerInfoWindow
。我从 MarkerInfoWindow
扩展了自己的 class CustomInfoWindow
。然后我尝试为包含在 InfoWindow
布局中的视图元素(tvDescribe
和 bubbleImage
)设置值,但是它出现了一个 NullPointerException
:
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);
}
}
我做错了什么?
也许你应该使用 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);
}