如何从扩展ItemizedOverlay的类中调用活动

时间:2012-03-16 23:15:46

标签: android popup

我的主要课程是校长延伸活动

使用此代码调用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);

没什么用。

请帮助我。

感谢

1 个答案:

答案 0 :(得分:0)

Activity传递到ItemizedOverlay(例如,通过构造函数)并将其用于startActivity()来电。