English 中文(简体)
i 罐头开始使用 地图调查活动
原标题:i cant use startActivity on Mapview

我想使用<条码> 启动(),但我可以 t。

我如何确定这一法典?

public class MyItemizedOverlay2 extends BalloonItemizedOverlay2<OverlayItem> {


    private static final Context getContext = null;
    private ArrayList<OverlayItem> m_overlays2 = new ArrayList<OverlayItem>();
    private Context c;
    private  int nIndex=0;
    private Context getbaseContext;

    public MyItemizedOverlay2(Drawable defaultMarker, MapView mapView) {
        super(boundCenter(defaultMarker), mapView);
        c = mapView.getContext();
    }

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

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

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

    @Override
    protected boolean onBalloonTap(int index) {
        Intent i = new Intent ("page1");
        startActivity(i);
     nIndex = index;
     ;
        //Toast.makeText(c, "Overlay2입니다. " + index,
        //      Toast.LENGTH_LONG).show();
        return true;
    }





}




public abstract class BalloonItemizedOverlay2<Item> extends ItemizedOverlay<OverlayItem> {

    private MapView mapView;
    private BalloonOverlayView2<?> balloonView2;
    private BalloonOverlayView<?> balloonView;
    private View clickRegion;
    private int viewOffset;
    final MapController mc;
    public  int indexN;




    /**
     * Create a new BalloonItemizedOverlay
     * 
     * @param defaultMarker - A bounded Drawable to be drawn on the map for each item in the overlay.
     * @param mapView - The view upon which the overlay items are to be drawn.
     */
    public BalloonItemizedOverlay2(Drawable defaultMarker, MapView mapView) {
        super(defaultMarker);
        this.mapView = mapView;
        viewOffset = 0;
        mc = mapView.getController();


    }

    /**
     * Set the horizontal distance between the marker and the bottom of the information
     * balloon. The default is 0 which works well for center bounded markers. If your
     * marker is center-bottom bounded, call this before adding overlay items to ensure
     * the balloon hovers exactly above the marker. 
     * 
     * @param pixels - The padding between the center point and the bottom of the
     * information balloon.
     */
    public void setBalloonBottomOffset(int pixels) {
        viewOffset = pixels;
    }

    /**
     * Override this method to handle a "tap" on a balloon. By default, does nothing 
     * and returns false.
     * 
     * @param index - The index of the item whose balloon is tapped.
     * @return true if you handled the tap, otherwise false.
     */




    protected boolean onBalloonTap(int index) {

        return false;
    }

    /* (non-Javadoc)
     * @see com.google.android.maps.ItemizedOverlay#onTap(int)
     */
    @Override
    protected final boolean onTap(int index) {

    indexN=index;



        boolean isRecycled;
        final int thisIndex;
        GeoPoint point;

        thisIndex = index;
        point = createItem(index).getPoint();

        if (balloonView2 == null) {
            balloonView2 = new BalloonOverlayView2<Object>(mapView.getContext(), viewOffset);


            clickRegion = (View) balloonView2.findViewById(R.id.balloon_inner_layout);
            isRecycled = false;
        } else {
            isRecycled = true;
        }

        balloonView2.setVisibility(View.GONE);



        switch(thisIndex){
        case 0:
            balloonView2.over21.setVisibility(View.VISIBLE);
            //balloonView.over1.setVisibility(View.INVISIBLE);
            break;
        case 1:
            balloonView2.over22.setVisibility(View.VISIBLE);
            //balloonView.over0.setVisibility(View.INVISIBLE);
            break;
        case 2:
            balloonView2.over23.setVisibility(View.VISIBLE);
            break;
        case 3:
            balloonView2.over24.setVisibility(View.VISIBLE);
            break;
        case 4:
            balloonView2.over25.setVisibility(View.VISIBLE);
            break;
        case 5:
            balloonView2.over26.setVisibility(View.VISIBLE);
            break;
        case 6:
            balloonView2.over27.setVisibility(View.VISIBLE);
            break;
        case 7:
            balloonView2.over28.setVisibility(View.VISIBLE);
            break;
        case 8:
            balloonView2.over29.setVisibility(View.VISIBLE);
            break;

        case 9:
            balloonView2.over30.setVisibility(View.VISIBLE);
            break;
        case 10:
            balloonView2.over31.setVisibility(View.VISIBLE);
            break;
        case 11:
            balloonView2.over32.setVisibility(View.VISIBLE);
            break;
        case 12:
            balloonView2.over33.setVisibility(View.VISIBLE);
            break;
        case 13:
            balloonView2.over34.setVisibility(View.VISIBLE);
            break;
        case 14:
            balloonView2.over35.setVisibility(View.VISIBLE);
            break;
        case 15:
            balloonView2.over36.setVisibility(View.VISIBLE);
            break;
        case 16:
            balloonView2.over37.setVisibility(View.VISIBLE);
            break;
        case 17:
            balloonView2.over38.setVisibility(View.VISIBLE);
            break;
        case 18:
            balloonView2.over39.setVisibility(View.VISIBLE);
            break;
        case 19:
            balloonView2.over40.setVisibility(View.VISIBLE);
            break;
        case 20:
            balloonView2.over41.setVisibility(View.VISIBLE);
            break;
        case 21:
            balloonView2.over42.setVisibility(View.VISIBLE);
            break;
        case 22:
            balloonView2.over43.setVisibility(View.VISIBLE);
            break;
        case 23:
            balloonView2.over44.setVisibility(View.VISIBLE);
            break;
        case 24:
            balloonView2.over45.setVisibility(View.VISIBLE);
            break;
        case 25:
            balloonView2.over46.setVisibility(View.VISIBLE);
            break;
        case 26:
            balloonView2.over47.setVisibility(View.VISIBLE);
            break;
        case 27:
            balloonView2.over48.setVisibility(View.VISIBLE);
            break;
        case 28:
            balloonView2.over49.setVisibility(View.VISIBLE);
            break;
        case 29:
            balloonView2.over50.setVisibility(View.VISIBLE);
            break;
        case 30:
            balloonView2.over51.setVisibility(View.VISIBLE);
            break;
        case 31:
            balloonView2.over52.setVisibility(View.VISIBLE);
            break;
        case 32:
            balloonView2.over32.setVisibility(View.VISIBLE);
            break;
        case 33:
            balloonView2.over33.setVisibility(View.VISIBLE);
            break;
        case 34:
            balloonView2.over34.setVisibility(View.VISIBLE);
            break;
        case 35:
            balloonView2.over35.setVisibility(View.VISIBLE);
            break;
        case 36:
            balloonView2.over36.setVisibility(View.VISIBLE);
            break;
        case 37:
            balloonView2.over37.setVisibility(View.VISIBLE);
            break;
        case 38:
            balloonView2.over38.setVisibility(View.VISIBLE);
            break;
        case 39:
            balloonView2.over39.setVisibility(View.VISIBLE);
            break;
        case 40:
            balloonView2.over40.setVisibility(View.VISIBLE);
            break;
        case 441:
            balloonView2.over41.setVisibility(View.VISIBLE);
            break;
        case 42:
            balloonView2.over42.setVisibility(View.VISIBLE);
            break;
        case 43:
            balloonView2.over43.setVisibility(View.VISIBLE);
            break;
        case 44:
            balloonView2.over44.setVisibility(View.VISIBLE);
            break;
        case 45:
            balloonView2.over45.setVisibility(View.VISIBLE);
            break;
        case 46:
            balloonView2.over46.setVisibility(View.VISIBLE);
            break;
        case 47:
            balloonView2.over47.setVisibility(View.VISIBLE);
            break;
        case 48:
            balloonView2.over48.setVisibility(View.VISIBLE);
            break;
        case 49:
            balloonView2.over49.setVisibility(View.VISIBLE);
            break;
        case 50:
            balloonView2.over50.setVisibility(View.VISIBLE);
            break;
        case 51:
            balloonView2.over51.setVisibility(View.VISIBLE);
            break;
        case 52:
            balloonView2.over52.setVisibility(View.VISIBLE);
            break;


        }
        //////////////////////////////


        List<Overlay> mapOverlays = mapView.getOverlays();
        if (mapOverlays.size() > 1) {
            hideOtherBalloons(mapOverlays);
        }

        balloonView2.setData(createItem(index));

        MapView.LayoutParams params = new MapView.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, point,
                MapView.LayoutParams.BOTTOM_CENTER);
        params.mode = MapView.LayoutParams.MODE_MAP;

        setBalloonTouchListener(thisIndex);

        balloonView2.setVisibility(View.VISIBLE);

        if (isRecycled) {
            balloonView2.setLayoutParams(params);
        } else {
            mapView.addView(balloonView2, params);
        }


        mc.animateTo(point);

        return true;
    }

    /**
     * Sets the visibility of this overlay s balloon view to GONE. 
     */
    private void hideBalloon() {
        if (balloonView2 != null) {

            balloonView2.setVisibility(View.GONE);


        }
    }

    /**
     * Hides the balloon view for any other BalloonItemizedOverlay instances
     * that might be present on the MapView.
     * 
     * @param overlays - list of overlays (including this) on the MapView.
     */
    private void hideOtherBalloons(List<Overlay> overlays) {

        for (Overlay overlay : overlays) {
            if (overlay instanceof BalloonItemizedOverlay2<?> && overlay != this) {
                ((BalloonItemizedOverlay2<?>) overlay).hideBalloon();

            }

        }

    }

    /**
     * Sets the onTouchListener for the balloon being displayed, calling the
     * overridden onBalloonTap if implemented.
     * 
     * @param thisIndex - The index of the item whose balloon is tapped.
     */
    private void setBalloonTouchListener(final int thisIndex) {

        try {
            @SuppressWarnings("unused")
            Method m = this.getClass().getDeclaredMethod("onBalloonTap", int.class);

            clickRegion.setOnTouchListener(new OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {

                    View l =  ((View) v.getParent()).findViewById(R.id.balloon_main_layout);
                    Drawable d = l.getBackground();

                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        int[] states = {android.R.attr.state_pressed};
                        if (d.setState(states)) {
                            d.invalidateSelf();
                        }
                        return true;
                    } else if (event.getAction() == MotionEvent.ACTION_UP) {
                        int newStates[] = {};
                        if (d.setState(newStates)) {
                            d.invalidateSelf();
                        }
                        // call overridden method
                        onBalloonTap(thisIndex);
                        return true;
                    } else {
                        return false;
                    }

                }
            });

        } catch (SecurityException e) {
            Log.e("BalloonItemizedOverlay", "setBalloonTouchListener reflection SecurityException");
            return;
        } catch (NoSuchMethodException e) {
            // method not overridden - do nothing
            return;
        }

    }



}
问题回答

为此:

mapView.getContext().startActivity();




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签