我遇到了这个问题:
当我从地图中点击一个标记时,我需要启动一个活动,在片段上可视化;
这是我的XML:
<LinearLayout
android:id="@+id/mylayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="560" >
<fragment
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:clickable="true"
android:name="com.google.android.gms.maps.MapFragment"
/>
</LinearLayout>
当使用点击一个标记时,我的ACTIVITY1桅杆呼叫ACTIVITY2(此处未写入) 基于Tabella数据构建:
@SuppressLint("NewApi")
public class ACTIVITY1 extends Activity {
. . . . . .
ArrayList<HashMap<String, String>> Tabella ();
. . . . . .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
mapView = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapview)).getMap();
. . . .
showmap(null);
. . . .
}
//prepare markers on map fragment
private void showMap(OnMarkerClickListener OnMarkerClickListener) {
arrM = new ArrayList<String> ();
mapView.setOnMarkerClickListener ( OnMarkerClickListener );
try {
for (int i=0 ; i<Tabella.size(); i++) {
HashMap<String, String> a = Tabella.get(i);
final String insegna = a.get("insegna");
String lat1 = a.get("latitudine");
String longi = a.get("longitudine");
if (lat1.equals("")) lat1 = "0.0";
if (longi.equals("")) longi = "0.0";
latitude = Double.parseDouble(lat1);
longitude = Double.parseDouble(longi);
cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude,longitude))
.zoom(17) // Sets the zoom
.build();
marker = mapView.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.snippet("" )
.icon(BitmapDescriptorFactory.fromResource(R.drawable.iconpoi))
.title(insegna));
mapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
marker.showInfoWindow();
arrM.add(marker.getId());
//mapView.setOnMarkerClickListener ( OnMarkerClickListener );
}
} catch (Exception e) {
e.printStackTrace();
}
}
//called when marker selected
public void onMarkerClick(Marker marker) {
. . .
Intent myIntent = new Intent(ACTIVITY1 .this,Activity2.class);
. .
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
ACTIVITY1 .this.startActivity(myIntent);
. .
}
}
为什么没有调用public void onMarkerClick(Marker marker)
?
有什么问题?
由于
答案 0 :(得分:0)
为什么公共无效onMarkerClick(标记标记)未被调用?
因为您调用了showmap(null)
,因此从未注册过监听器。