Android 谷歌地图api v2-启动活动表单标记

Android 谷歌地图api v2-启动活动表单标记,android,google-maps-android-api-2,Android,Google Maps Android Api 2,我有一个问题: 当点击地图上的一个标记时,我需要启动一个活动,显示在片段上 这是我的XML的一部分: <LinearLayout android:id="@+id/mylayout" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="560" > <fragment android:id="

我有一个问题:

当点击地图上的一个标记时,我需要启动一个活动,显示在片段上

这是我的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>

我的活动1当用户点击一个标记时,mast调用活动2(此处未写入) 基于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);
     . . 

 }  

 }
@SuppressLint(“NewApi”)
公共类活动1扩展活动{
. . . . . .
ArrayList Tabella();
. . . . . .
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
mapView=((MapFragment)getFragmentManager().findFragmentById(R.id.mapView)).getMap();
. . . . 
showmap(空);
. . . . 
}
//在地图片段上准备标记
私有void showMap(OnMarkerClickListener OnMarkerClickListener){
arrM=newarraylist();
mapView.setOnMarkerClickListener(OnMarkerClickListener);
试一试{
对于(int i=0;i
为什么不调用markerclick(Marker-Marker)上的public void


因为您调用了
showmap(null)
,因此从未注册过侦听器。

@user1812637:没有证据表明您编写了“正确的代码”。当然,您不能将
null
传递给
showmap()
,基于您当前的实现。您需要传递一个实际的
OnMarkerClickListener
对象。从何处获取该对象取决于您。下面是一个示例项目,演示了如何使用
OnMarkerClickListener