2012-03-16 49 views
0

我主类的类调用一个活动是主要的扩展活动如何从扩大ItemizedOverlay

与此代码调用MiMapa类:

switch(v.getId()){ 
     case R.id.presentLocation_button: 
      Log.i("Button","Button 3 pushed"); 
      Intent m = new Intent(this, MiMapa.class); 
      startActivity(m); 
     break; 

工作完美。

MiMapa类是:

public class MiMapa extends MapActivity implements LocationListener { 

我有这样的方法:

public void setOverlay1(){ 
     int foodLength = foodItem.length; 
     // Create itemizedOverlay2 if it doesn't exist and display all three items 
     if(! foodIsDisplayed){ 
     mapOverlays = mapView.getOverlays();  
     drawable1 = this.getResources().getDrawable(R.drawable.golf); 
     itemizedOverlay1 = new Ofertas(drawable1); 
     // Display all three items at once 
     for(int i=0; i<foodLength; i++){ 
      itemizedOverlay1.addOverlay(foodItem[i]); 
     } 
     mapOverlays.add(itemizedOverlay1); 
     foodIsDisplayed = !foodIsDisplayed; 
     // Remove each item successively with button clicks 
     } else {    
      itemizedOverlay1.removeItem(itemizedOverlay1.size()-1); 
      if((itemizedOverlay1.size() < 1)) foodIsDisplayed = false; 
     }  
     // Added symbols will be displayed when map is redrawn so force redraw now 
     mapView.postInvalidate(); 
    } 

现在的问题。

到Ofertas类(公共类Ofertas扩展ItemizedOverlay {)

在自来水方法我的代码是:

protected boolean onTap(int i){ 
     GeoPoint gpoint = myOverlays.get(i).getPoint(); 

     double lat = gpoint.getLatitudeE6()/1e6; 
     double lon = gpoint.getLongitudeE6()/1e6; 

     String toast = "Title: "+myOverlays.get(i).getTitle(); 
     toast += "\nText: "+myOverlays.get(i).getSnippet(); 
     toast += "\nSymbol coordinates: Lat = "+lat+" Lon = "+lon+" (microdegrees)"; 
     Toast.makeText(principal.context, toast, Toast.LENGTH_LONG).show(); 

     Intent intent = new Intent(); 
     intent.setClass(principal.context,Popup.class); 
     principal.context.startActivity(intent); 
     intent.putExtra("message", "My popup number " + mCount); 
     mCount++; 
     //startActivity(intent); 
     return(true); 
    } 

,但不起作用。我试过 intent.setClass(MiMapa.context,Popup.class); 或 intent.setClass(principal.this,Popup.class); 或 intent.setClass(MiMapa.this,Popup.class);

没有工作。

请帮帮我。

感谢

回答

0

通过你的Activity到您的ItemizedOverlay(例如,通过构造函数),并使用你的电话startActivity()