0

我是新來的機器人,但我設法遵循幾個教程讓我開始..我想要做的是使用三個按鈕出現一旦用戶已經觸摸屏幕上的更多警報對話框更多比2(秒)我遇到的問題是ALERTDIALOG框不會出現在地圖上,當我啓動它..我沒有得到任何錯誤?所以有人可以幫助我。AlertDialog不會出現在GoogleMap上。恐慌

下面是我的代碼....

long start; 
    long stop; 

    //reference map from citymap.xml file 
    map = (MapView) findViewById(R.id.mvMain); 

    // Enable zoom features 
    map.setBuiltInZoomControls(false); 

    //Declaring the instance Interaction 
    Interact t = new Interact(); 

    //declaring a list of overlays 
    List<Overlay> overlayList = map.getOverlays(); 

    // interact t in to overlay list. 
    overlayList.add(t); 

    class Interact extends Overlay {  
     public boolean OnTouchEvent(MotionEvent e, MapView m){ 
     // initiating motion event action down 
     if(e.getAction() == MotionEvent.ACTION_DOWN){ 
     // set start time 
      start = e.getEventTime(); 

     } 
     // Initiating motion event action up: when the user stops on touch event 
     if(e.getAction() == MotionEvent.ACTION_UP){ 
      // set end time 
      stop = e.getEventTime(); 
     } 
     // calculating the time to project an alert dialog 
     if (stop > 1500){ 
      Toast.makeText(CityMap.this, "toast meee", 50000).show(); 
      //perform an action, create alert dialog box 
      AlertDialog.Builder builder = new AlertDialog.Builder(CityMap.this).create(); 
      builder.setTitle("Select an Option"); 
      builder.setCancelable(true); 
      builder.setPositiveButton("Place pint Point", new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface dialog, int which) { 
        // TODO Auto-generated method stub 

       } 
      }); 
builder.create(); 
      builder.show(); 
      return true; 
     } 
     return true; 
+0

嘗試爲警報對話框指定z-index和背景顏色。 – Unknown 2012-03-30 02:21:53

回答

0

我想你搞砸了一下最後的if語句。嘗試第二次返回false。

一下我:

if (stop - start > 1500) { 
      // perform some action 
      AlertDialog alert = new AlertDialog.Builder(Main.this).create(); 
      alert.setTitle("Pick an option"); 
      alert.setMessage("Pick an option dude!"); 

      alert.setButton("Place a pin", 
        new DialogInterface.OnClickListener() { 

         public void onClick(DialogInterface dialog, 
           int which) { 
          // TODO Auto-generated method stub 

         } 
        }); 

希望這有助於;)

0

對於@Pepys:此方法已被棄用。您應該使用

alert.setPositiveButton("your text", new DialogInterface.OnClickListener() { 
public void onClick(DialogInterface dialog, int which) {... 
}});