Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:51:31+00:00 2026-06-14T22:51:31+00:00

i used this tutorial http://crazyandroidian.blogspot.com/2011/10/custom-mapview-popup-in-android.html Please tell me how to add an image in

  • 0

i used this tutorial http://crazyandroidian.blogspot.com/2011/10/custom-mapview-popup-in-android.html Please tell me how to add an image in a balloon tab. I want to add a location image in a marker point bubble. This code just shows a text message but no image.

package com.readystatesoftware.mapviewballoons;
import mapviewballoons.example.R;
import java.lang.reflect.Method;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public abstract class BalloonItemizedOverlay<Item> extends ItemizedOverlay<OverlayItem>  {
  private MapView mapView;
  private BalloonOverlayView balloonView;
  private View clickRegion;
  private int viewOffset;
  final MapController mc;

  public BalloonItemizedOverlay(Drawable defaultMarker, MapView mapView) {
    super(defaultMarker);
    this.mapView = mapView;
    viewOffset = 0;
    mc = mapView.getController();
  }
  public void setBalloonBottomOffset(int pixels) {
    viewOffset = pixels;
  }
  protected boolean onBalloonTap(int index) {
    return false;
  }
  @Override
  protected final boolean onTap(int index) {
    boolean isRecycled;
    final int thisIndex;
    GeoPoint point;
    thisIndex = index;
    point = createItem(index).getPoint();
    if (balloonView == null) {
      balloonView = new BalloonOverlayView(mapView.getContext(), viewOffset);
      clickRegion = (View) balloonView.findViewById(R.id.balloon_inner_layout);
      isRecycled = false;
    } else {
      isRecycled = true;
    }
    balloonView.setVisibility(View.GONE);
    List<Overlay> mapOverlays = mapView.getOverlays();
    if (mapOverlays.size() > 1) {
      hideOtherBalloons(mapOverlays);
    }
    balloonView.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);
    balloonView.setVisibility(View.VISIBLE);
    if (isRecycled) {
      balloonView.setLayoutParams(params);
    } else {
      mapView.addView(balloonView, params);
    }
    mc.animateTo(point);
    return true;
  }
  /**
    * Sets the visibility of this overlay's balloon view to GONE.
  */
  private void hideBalloon() {
    if (balloonView != null) {
      balloonView.setVisibility(View.GONE);
    }
  }
  private void hideOtherBalloons(List<Overlay> overlays) {
    for (Overlay overlay : overlays) {
      if (overlay instanceof BalloonItemizedOverlay<?> && overlay != this) {
        ((BalloonItemizedOverlay<?>) overlay).hideBalloon();
      }
    }
  }
  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;
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:51:32+00:00Added an answer on June 14, 2026 at 10:51 pm

    I believe that you need to create a layout for your balloon. In this tutorial the author creates a balloon view and has a balloon.xml To display an image you would put the correct image view in the XML file. Kind of like trying to display text and images in a list view where you need a layout for the rows. Unless i missed it you need to define this in your R.id.balloon_main_layout

    You might even need to create a class extending OverlayItem because each item on the map will probably have a different picture associated with it. If you create an item that extends OverlayItem then you can pass in a picture or have functions to retrieve the picture when the overlay is created.

    EDIT: Your example works exactly the way it describes. The tutorial that you linked to in your comments solves your problem. The tutorial displays text with an ImageView next to it. The images are given to you at the bottom of the tutorial you have to save them to a folder named drawable in your res directory.

    Edit: I actually just got the code that you used working. It displays a blank map because i didnt put my api key in but the popup has text and a cancel button next to it that is the image view inflated from balloon_map_overlay.xml

    You can extend the OverlayItem like this Include a picture:

    import android.graphics.Rect;
    import android.graphics.drawable.Drawable;
    
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.OverlayItem;
    
    public class MyItem extends OverlayItem{
    
        Drawable balloonPic = null;
        Rect mBounds = null;
        public MyItem(GeoPoint point, String title, String snippet, Drawable draw, Rect bounds) {
            super(point, title, snippet);
    
            mBounds = bounds;
            //0,0 position is the geopoint on the map. Positive is going right and down. negative goes left and up. setBounds accepts (leftBound, topbound, right bound, bottom bound)
            draw.setBounds(-draw.getIntrinsicWidth()/2, -draw.getIntrinsicHeight(), draw.getIntrinsicWidth()/2, 0);
            this.setBalloonPic(draw);
    
        }
    
        @Override
        public void setBalloonPic(Drawable draw) {
    
            balloonPic = draw;
    
        }
        @Override
        public Drawable getBalloonPic() {
    
            return balloonPic;
    
        }
    
    }
    

    In Your balloon overlayview you need to set your data for the pictures when the overlayitems get created. Ill leave that up to you but the example shows how to access the OverlayItem’s get methods and the above code hints at having getters and setters for the Image that you want to display. Otherwise it will display the same image on every balloon.

    public void setData(OverlayItem item) {
        layout.setVisibility(VISIBLE);
        if (item.getTitle() != null) {
        title.setVisibility(VISIBLE);
        title.setText(item.getTitle());
        } else {
        title.setVisibility(GONE);
        }
        if (item.getSnippet() != null) {
        snippet.setVisibility(VISIBLE);
        snippet.setText(item.getSnippet());
        } else {
        snippet.setVisibility(GONE);
        }
    

    P.S. your public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> needs to be
    public class MyItemizedOverlay extends BalloonItemizedOverlay<MyItem>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used this tutorial to rename a view controller http://iosdeveloperzone.com/2011/05/14/how-to-rename-a-class-using-refactoring-in-xcode-4/ Basically just switch to
I have used the signalR chat app (as laid out in this tutorial http://sergiotapia.com/2011/09/signalr-with-mvc3-chat-app-build-asynchronous-real-time-persistant-connection-websites/
If you create the app described in this tutorial http://developer.android.com/resources/tutorials/views/hello-datepicker.html change the date, and
I used this tutorial http://mobiforge.com/developing/story/using-google-maps-android to display Map view and set onTouch event to
I've installed the Android SDK using this tutorial http://www.youtube.com/watch?v=xDjkHJVC0R0 and i used a different
I've used the exact files from this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ The ideea is to submit
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I originally used this tutorial - http://icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/ to put twitter into my app. It
I used this tutorial: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html To build my first form/create user app, but it
I have used this tutorial (http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page) to design a site with a footer that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.