![](/img/trans.png)
[英]How to POST get response information on alert dialog when clicking submit?
[英]Alert dialog layout when clicking marker
我搜索了如何在單擊 google maps api v3 上的標記時顯示警報對話框布局。 我在 stackoverflow 上找到了一個代碼,但對我來說它不起作用。 這是我的地圖類
package com.myapp;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import android.graphics.Color;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;
public class MyClass extends FragmentActivity implements OnMarkerClickListener {
private GoogleMap googleMap;
private int mapType = GoogleMap.MAP_TYPE_NORMAL;
private Marker marker1;
ImageButton imageButton1;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
FragmentManager fragmentManager = getFragmentManager();
MapFragment mapFragment = (MapFragment) fragmentManager.findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
// Getting LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sLatLng12 = new LatLng(34.0522, 118.2437);
marker1 = googleMap.addMarker(new MarkerOptions()
.position(sLatLng12)
.title("Marker title")
.snippet("Marker snippet")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon)));
public boolean onMarkerClick(Marker marker1) {
if(this.marker1.equals(marker1)){
AlertDialog.Builder alertadd = new AlertDialog.Builder(MyClass.this);
LayoutInflater factory = LayoutInflater.from(MyClass.this);
final View view = factory.inflate(R.layout.dialog_layout, null);
alertadd.setView(view);
alertadd.show();
}
return false;
}
}
地圖打開正常並顯示我的標記。 但是當我點擊時,它沒有顯示任何警報對話框。 提前致謝!
如果 if 塊中的代碼運行,該方法應該返回 true。 如果該方法返回 false,則單擊事件將不會傳遞給您已注冊的偵聽器。
public boolean onMarkerClick(Marker marker1) {
if(this.marker1.equals(marker1)){
AlertDialog.Builder alertadd = new AlertDialog.Builder(MyClass.this);
LayoutInflater factory = LayoutInflater.from(MyClass.this);
final View view = factory.inflate(R.layout.dialog_layout, null);
alertadd.setView(view);
alertadd.show();
return true;
}
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.