2014-04-26 80 views
2

*我創建了一個警告對話框,點擊標記
*後顯示,但是當我點擊標記時,它會使應用程序崩潰。
*可能是什麼問題?我有什麼遺漏?
由於提前
AlertDialog沒有顯示當我點擊標記

googleMap.setOnMarkerClickListener(new OnMarkerClickListener() { 

      @SuppressWarnings("deprecation") 
      @Override 
      public boolean onMarkerClick(Marker marker) { 

       showAlertDialog(); 

       return false; 

      } 


     }); 



private void showAlertDialog() { 

    AlertDialog alert = new AlertDialog.Builder(
      getBaseContext()).create(); 

    alert.setTitle("Location Selected"); 
    alert.setMessage("Add this Location to your"); 
    alert.setButton("Places", 

      new DialogInterface.OnClickListener() { 

       //code goes here 
      }); 
    alert.setButton("Activities", 
      new DialogInterface.OnClickListener() { 

       //code goes here 
       } 

      }); 
    alert.show(); 

} 
+0

你可以請張貼您的logcat片斷更多的瞭解呢? –

回答

0
@SuppressWarnings("deprecation") 
    void showAlertDialog(final LatLng markerPosition) { 

     AlertDialog alertDialog = new AlertDialog.Builder(GoogleMapViewer.this) 
       .create(); 

     alertDialog.setTitle("Location Selected"); 

     alertDialog.setMessage("Add this Location to your"); 

     alertDialog.setButton2("Places", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       Toast.makeText(getApplicationContext(), 
         "You clicked on Places", Toast.LENGTH_SHORT).show(); 
      } 
     }); 

     alertDialog.setButton3("Activities", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         Intent act_intent = new Intent(); 
         act_intent.setClass(GoogleMapViewer.this, 
           addActivities.class); 
         act_intent.putExtra("username", savedUserName); 
         act_intent 
           .putExtra("latitude", markerPosition.latitude); 
         act_intent.putExtra("longitude", 
           markerPosition.longitude); 
         startActivity(act_intent); 

        } 
       }); 

     alertDialog.show(); 
    } 
0

嘗試的

AlertDialog.Builder alert = new AlertDialog.Builder(getBaseContext()).create(); 

代替

AlertDialog alert = new AlertDialog.Builder(getBaseContext()).create(); 
+0

據說無法從AlertDialog轉換爲AlertDialog.Builder – phpnerd