0

我正在使用一個android項目。現在我正在創建一個定製的覆蓋類。在這個類內部,我在一個警告對話框監聽器上遇到了一個問題。我無法在偵聽器中加載任何意圖。我應該怎麼做?這裏是我的代碼..加載類時警報對話框偵聽器出錯

import java.util.ArrayList; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.graphics.drawable.Drawable; 
import android.view.MotionEvent; 
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.ItemizedOverlay; 
import com.google.android.maps.MapView; 
import com.google.android.maps.OverlayItem; 

/** 
* Class used to place marker or any overlay items on Map 
* */ 
public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> { 

     private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>(); 

     private Context context; 

     public AddItemizedOverlay(Drawable defaultMarker) { 
      super(boundCenterBottom(defaultMarker)); 
     } 

     public AddItemizedOverlay(Drawable defaultMarker, Context context) { 
      this(defaultMarker); 
      this.context = context; 
     } 

     @Override 
     public boolean onTouchEvent(MotionEvent event, MapView mapView) 
     { 

      if (event.getAction() == 1) { 
       GeoPoint geopoint = mapView.getProjection().fromPixels(
        (int) event.getX(), 
        (int) event.getY()); 
       // latitude 
       double lat = geopoint.getLatitudeE6()/1E6; 
       // longitude 
       double lon = geopoint.getLongitudeE6()/1E6; 
       //Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show(); 
      } 
      return false; 
     } 

     @Override 
     protected OverlayItem createItem(int i) { 
      return mapOverlays.get(i); 
     } 

     @Override 
     public int size() { 
      return mapOverlays.size(); 
     } 

     @Override 
     protected boolean onTap(int index) { 
     OverlayItem item = mapOverlays.get(index); 
     AlertDialog.Builder dialog = new AlertDialog.Builder(this.context); 
     dialog.setTitle(item.getTitle()); 
     dialog.setMessage(item.getSnippet()); 
     dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 

       startActivity(new Intent(AddItemizedOverlay.this,SinglePlaceActivity.class)); 
      } 
     }) 
      .setNegativeButton("No",new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
        // if this button is clicked, just close 
        // the dialog box and do nothing 
        dialog.cancel(); 
//     MainActivity.this.finish(); 
       } 
      }); 
     dialog.show(); 
     return true; 
     } 

     public void addOverlay(OverlayItem overlay) { 
      mapOverlays.add(overlay); 
     } 

     public void populateNow(){ 
      this.populate(); 
     } 

    } 

,並得到了一個錯誤如下 enter image description here

回答

1

使用Context開始活動。

Intent intent = new Intent(context, RosettaActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(intent); 
+0

現在它顯示錯誤的context.setFlags –

+0

我bad..see我的編輯... –

+1

你現在是正確的謝謝你。 –