Я не знаю, поможет ли это вам. Мне нужно было создать CustomInfoBubble
для моего проекта. Что я сделал, так это расширил класс InfoWindow
по умолчанию и передал ему свой собственный макет пузырьков. Примерно так: http://mobiledevstories.wordpress.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/
Мой класс Java MapCustomInfoBubble
выглядит так:
public class MapCustomInfoBubble extends InfoWindow {
public MapCustomInfoBubble(MapView mapView) {
super(R.layout.map_infobubble_black, mapView);//my custom layout and my mapView
}
@Override
public void onClose() {
//by default, do nothing
}
@Override
public void onOpen(Object item) {
Marker marker = (Marker)item; //the marker on which you click to open the bubble
String title = marker.getTitle();
if (title == null)
title = "";
Button moreInfo = (Button)mView.findViewById(R.id.bubble_moreinfo);//the button that I have in my XML;
moreInfo.setText(title);
moreInfo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
gotoMoreInfoWindow();//custom method; starts another activity
}
});
}
}
В моем файле XML у меня есть:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/map_infobubble_black" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:id="@+id/bubble_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:maxEms="17"
android:layout_gravity="left"
android:layout_weight="1"
android:text="Title" />
<Button android:id="@+id/bubble_moreinfo"
android:background="@drawable/map_btn_moreinfo"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0" />
</LinearLayout>
</LinearLayout>
Где-то еще в моем коде я использую:
Marker wp = new Marker(mapView);
wp.setPosition(new GeoPoint(mylocation.getMyLocation()));
wp.setTitle(editTextName.getText().toString());
wp.setInfoWindow(new MapCustomInfoBubble(mapView));
mapView.getOverlays().add(wp);
mapView.invalidate();
В моем коде я установил текст на button
с заголовком Marker
. Marker
— это элемент, на который я нажимаю. Если вы хотите поместить информацию о большем количестве маркеров в один и тот же InfoWindow
(внутри ListView
), я думаю, вам нужно знать заранее, что это будет за информация.
Я считаю, что вы можете поместить любой код внутрь onOpen()
, однако я не уверен, что это хорошая практика. Вы можете попробовать создать собственный Constructor
и поместить туда свою логику. Он должен работать. Вам нужно передать Resource Id
(макет) и mapView
суперконструктору, чтобы он вернул допустимый объект mView
.
person
nightfixed
schedule
02.04.2014