Android 如何设置要在MarkerInfoWindow中查看的值?
我使用OSMBonusPack库在地图上创建标记。从这个库中,我使用Android 如何设置要在MarkerInfoWindow中查看的值?,android,osmdroid,Android,Osmdroid,我使用OSMBonusPack库在地图上创建标记。从这个库中,我使用MarkerInfoWindow。我从MarkerInfoWindow扩展了自己的类CustomInfoWindow。然后,我尝试设置视图元素(tvdribe和bubbleImage)的值,这些元素包含在InfoWindow的布局中,但其中出现了NullPointerException: public class CustomInfoWindow extends MarkerInfoWindow { TextView t
MarkerInfoWindow
。我从MarkerInfoWindow
扩展了自己的类CustomInfoWindow
。然后,我尝试设置视图元素(tvdribe
和bubbleImage
)的值,这些元素包含在InfoWindow
的布局中,但其中出现了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);
}