title: Google map Current location Balloon overlay?
body: <p>I am creating Google map Current location Balloon overlay.</p>
  
  <p>I used android-mapviewballoons this code to show balloon.</p>
  
  <p>Here Current location display is working. When i click on marker, error will come(BalloonOverlayView 57,38 lines and BalloonItemizedOverlay 87,188,76 lines ).</p>
  
  <p>Where is error i know but i am no understanding that part, Any one please help me</p>
  
  <p>This is LogCat error</p>
  
  <pre><code>02-01 05:09:31.606: W/Trace(1250): Unexpected value from nativeGetEnabledTags: 0
  02-01 05:09:31.636: I/System.out(1250): 6666666666666
  02-01 05:09:31.636: I/System.out(1250): 77777777
  02-01 05:09:31.646: I/System.out(1250): 7777888888
  02-01 05:09:31.656: I/System.out(1250): 33333333
  02-01 05:09:31.756: I/System.out(1250): 1111111
  02-01 05:09:31.756: W/Trace(1250): Unexpected value from nativeGetEnabledTags: 0
  02-01 05:09:31.756: E/InputEventReceiver(1250): Exception dispatching input event.
  02-01 05:09:31.766: E/MessageQueue-JNI(1250): Exception in MessageQueue callback: handleReceiveCallback
  02-01 05:09:31.836: D/dalvikvm(1250): GC_CONCURRENT freed 275K, 11% free 3508K/3904K, paused 35ms+27ms, total 163ms
  02-01 05:09:31.926: E/MessageQueue-JNI(1250): java.lang.NullPointerException
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.sygnet.locationingooglemap.BalloonOverlayView.setupView(BalloonOverlayView.java:57)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.sygnet.locationingooglemap.BalloonOverlayView.&lt;init&gt;(BalloonOverlayView.java:38)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.sygnet.locationingooglemap.BalloonItemizedOverlay.createBalloonOverlayView(BalloonItemizedOverlay.java:87)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.sygnet.locationingooglemap.BalloonItemizedOverlay.createAndDisplayBalloonOverlay(BalloonItemizedOverlay.java:188)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.sygnet.locationingooglemap.BalloonItemizedOverlay.onTap(BalloonItemizedOverlay.java:76)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:358)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:562)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.google.android.maps.MapView.onTouchEvent(MapView.java:685)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.View.dispatchTouchEvent(View.java:7239)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at  android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.View.dispatchPointerEvent(View.java:7419)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.os.MessageQueue.nativePollOnce(Native Method)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.os.MessageQueue.next(MessageQueue.java:125)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.os.Looper.loop(Looper.java:124)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at android.app.ActivityThread.main(ActivityThread.java:5039)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at java.lang.reflect.Method.invokeNative(Native Method)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at java.lang.reflect.Method.invoke(Method.java:511)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  02-01 05:09:31.926: E/MessageQueue-JNI(1250):   at dalvik.system.NativeStart.main(Native Method)
  02-01 05:09:32.006: D/AndroidRuntime(1250): Shutting down VM
  02-01 05:09:32.006: W/dalvikvm(1250): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
  02-01 05:09:32.096: E/AndroidRuntime(1250): FATAL EXCEPTION: main
  02-01 05:09:32.096: E/AndroidRuntime(1250): java.lang.NullPointerException
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.sygnet.locationingooglemap.BalloonOverlayView.setupView(BalloonOverlayView.java:57)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.sygnet.locationingooglemap.BalloonOverlayView.&lt;init&gt;(BalloonOverlayView.java:38)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.sygnet.locationingooglemap.BalloonItemizedOverlay.createBalloonOverlayView(BalloonItemizedOverlay.java:87)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.sygnet.locationingooglemap.BalloonItemizedOverlay.createAndDisplayBalloonOverlay(BalloonItemizedOverlay.java:188)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.sygnet.locationingooglemap.BalloonItemizedOverlay.onTap(BalloonItemizedOverlay.java:76)
   02-01 05:09:32.096: E/AndroidRuntime(1250):    at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
   02-01 05:09:32.096: E/AndroidRuntime(1250):    at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:358)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:562)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:685)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.View.dispatchTouchEvent(View.java:7239)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at   android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
   02-01 05:09:32.096: E/AndroidRuntime(1250):    at android.view.View.dispatchPointerEvent(View.java:7419)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
   02-01 05:09:32.096: E/AndroidRuntime(1250):    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.os.MessageQueue.nativePollOnce(Native Method)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.os.MessageQueue.next(MessageQueue.java:125)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.os.Looper.loop(Looper.java:124)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at android.app.ActivityThread.main(ActivityThread.java:5039)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at java.lang.reflect.Method.invoke(Method.java:511)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  02-01 05:09:32.096: E/AndroidRuntime(1250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
   02-01 05:09:32.096: E/AndroidRuntime(1250):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>This is BalloonItemizedOverlay.java</p>
  
  <pre><code> public abstract class BalloonItemizedOverlay&lt;Item extends OverlayItem&gt; extends ItemizedOverlay&lt;Item&gt; {
  
  private static final long BALLOON_INFLATION_TIME = 300;
  private static Handler handler = new Handler();
  
  private MapView mapView;
  private BalloonOverlayView&lt;Item&gt; balloonView;
  private View clickRegion;
  private View closeRegion;
  private int viewOffset;
  final MapController mc;
  private Item currentFocusedItem;
  private int currentFocusedIndex;
  
  private boolean showClose = true;
  private boolean showDisclosure = false;
  private boolean snapToCenter = true;
  private static boolean isInflating = false;
  
  public BalloonItemizedOverlay(Drawable defaultMarker, MapView mapView) {
      super(defaultMarker);
      this.mapView = mapView;
      viewOffset = 0;
      mc = mapView.getController();
  }
  
  public void setBalloonBottomOffset(int pixels) {
      viewOffset = pixels;
  }
  public int getBalloonBottomOffset() {
      return viewOffset;
  }
  
  protected boolean onBalloonTap(int index, Item item) {
      return false;
  }
  
  protected void onBalloonOpen(int index) {}
  
  @Override
  public final boolean onTap(int index) {
  
      handler.removeCallbacks(finishBalloonInflation);
      isInflating = true;
      handler.postDelayed(finishBalloonInflation, BALLOON_INFLATION_TIME);
      System.out.println("6666666666666");
      currentFocusedIndex = index;
      currentFocusedItem = createItem(index);
      setLastFocusedIndex(index);
  
      onBalloonOpen(index);
      createAndDisplayBalloonOverlay();
  
      if (snapToCenter) {
          mc.animateTo(currentFocusedItem.getPoint());
      }
  
      return true;
  }
  
  protected BalloonOverlayView&lt;Item&gt; createBalloonOverlayView() {
      System.out.println("77777777");
      return new BalloonOverlayView&lt;Item&gt;(getMapView().getContext(), getBalloonBottomOffset());
  }
  
  protected MapView getMapView() {
      System.out.println("7777888888");
      return mapView;
  
  }
  
  public void hideBalloon() {
      if (balloonView != null) {
          balloonView.setVisibility(View.GONE);
          System.out.println("888888");
      }
      currentFocusedItem = null;
  }
  
  private void hideOtherBalloons(List&lt;Overlay&gt; overlays) {
  
      for (Overlay overlay : overlays) {
          if (overlay instanceof BalloonItemizedOverlay&lt;?&gt; &amp;&amp; overlay != this) {
              ((BalloonItemizedOverlay&lt;?&gt;) overlay).hideBalloon();
              System.out.println("88886666666666688");
          }
      }       
  }
  
  public void hideAllBalloons() {
      if (!isInflating) {
          List&lt;Overlay&gt; mapOverlays = mapView.getOverlays();
          if (mapOverlays.size() &gt; 1) {
              hideOtherBalloons(mapOverlays);
          }
          hideBalloon();
      }
  }
  
  private OnTouchListener createBalloonTouchListener() {
      return new OnTouchListener() {
  
          double startX;
          double startY;
  
          public boolean onTouch(View v, MotionEvent event) {
  
  //              View l =  ((View) v.getParent()).findViewById(R.id.balloon_main_layout);
              Drawable d = v.getBackground();
  
              //Event Action Down
              if (event.getAction() == MotionEvent.ACTION_DOWN) {
                  int[] states = {android.R.attr.state_pressed};
                  if (d.setState(states)) {
                      d.invalidateSelf();
                      System.out.println("12122121212");
                  }
                  startX = event.getX();
                  startY = event.getY();
                  System.out.println("1111222211112222");
                  return true;
              } 
  
              //Event Action Up
              else if (event.getAction() == MotionEvent.ACTION_UP) {
                  int newStates[] = {};
                  if (d.setState(newStates)) {
                      d.invalidateSelf();
                      System.out.println("0000011111");
                  }
                  if (Math.abs(startX - event.getX()) &lt; 40 &amp;&amp; Math.abs(startY - event.getY()) &lt; 40 ) {
                      // call overridden method
                      onBalloonTap(currentFocusedIndex, currentFocusedItem);
                      System.out.println("12345678");
                  }
                  return true;
              } else {
                  return false;
              }               
          }
      };
  }
  
  @Override
  public Item getFocus() {
      return currentFocusedItem;
  }
  
  @Override
  public void setFocus(Item item) {
      super.setFocus(item);   
      currentFocusedIndex = getLastFocusedIndex();
      currentFocusedItem = item;
      if (currentFocusedItem == null) {
          hideBalloon();
      } else {
          createAndDisplayBalloonOverlay();
      }   
  }
  
  private boolean createAndDisplayBalloonOverlay(){
      boolean isRecycled;
      if (balloonView == null) {
          balloonView = createBalloonOverlayView();
          clickRegion = (View) balloonView.findViewById(R.id.balloon_inner_layout);
  
          clickRegion.setOnTouchListener(createBalloonTouchListener());
          closeRegion = (View) balloonView.findViewById(R.id.balloon_close);
          if (closeRegion != null) {
              if (!showClose) {
                  closeRegion.setVisibility(View.GONE);
                  System.out.println("aaaaaaaa");
              } else {
                  closeRegion.setOnClickListener(new OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          hideBalloon();  
                          System.out.println("bbbbbbb");
                      }
                  });
              }
          }
  
          if (showDisclosure &amp;&amp; !showClose) {
              View v = balloonView.findViewById(R.id.balloon_disclosure);
              if (v != null) {
                  v.setVisibility(View.VISIBLE);
                  System.out.println("cccccccc");
              }
          }
          isRecycled = false;
      } 
      else {
          isRecycled = true;
      }
  
      balloonView.setVisibility(View.GONE);
  
      List&lt;Overlay&gt; mapOverlays = mapView.getOverlays();
      if (mapOverlays.size() &gt; 1) {
          hideOtherBalloons(mapOverlays);
      }
  
      if (currentFocusedItem != null)
          balloonView.setData(currentFocusedItem);
  
      GeoPoint point = currentFocusedItem.getPoint();
      MapView.LayoutParams params = new MapView.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, point,
              MapView.LayoutParams.BOTTOM_CENTER);
      params.mode = MapView.LayoutParams.MODE_MAP;
  
      balloonView.setVisibility(View.VISIBLE);
      System.out.println("dddddddd");
      if (isRecycled) {
          balloonView.setLayoutParams(params);
      } 
      else {
          mapView.addView(balloonView, params);
      }
  
      return isRecycled;
  } 
  
  public void setShowClose(boolean showClose) {
      this.showClose = showClose;
  }
  
  public void setShowDisclosure(boolean showDisclosure) {
      this.showDisclosure = showDisclosure;
  }
  
  public void setSnapToCenter(boolean snapToCenter) {
      this.snapToCenter = snapToCenter;
  }
  
  public static boolean isInflating() {
      return isInflating;
  }
  
  private static Runnable finishBalloonInflation = new Runnable() {
      public void run() {
          isInflating = false;
      }
  };
  
  }
  </code></pre>
  
  <p>This is BalloonOverlayView.java</p>
  
  <pre><code>public class BalloonOverlayView&lt;Item extends OverlayItem&gt; extends FrameLayout  {
  
  LinearLayout layout;
  private TextView title;
  MainActivity main;
  private CharSequence tvLocation;
  
  
  public BalloonOverlayView(Context context, int balloonBottomOffset) {
  
      super(context);
  
      setPadding(10, 0, 10, balloonBottomOffset);
  
      layout = new LimitLinearLayout(context);
      layout.setVisibility(VISIBLE);
  
      setupView(context, layout);
  
      FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      params.gravity = Gravity.NO_GRAVITY;
  
      addView(layout, params);
  }
  
  protected void setupView(Context context, ViewGroup parent) {
      try {
      LayoutInflater inflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View v = inflater.inflate(R.layout.balloon_overlay, parent);
      title = (TextView) v.findViewById(R.id.balloon_item_title);
      System.out.println("00000000000");
      }
      catch(Exception e)
      {
          System.out.println("1111111");
          title.setText(tvLocation);
      }
  
  //      title.setText(tvLocation);
  }
  
  public void setData(Item item) {
      layout.setVisibility(VISIBLE);
      setBalloonData(item, layout);
      System.out.println("1113333");
  }
  
  protected void setBalloonData(Item item, ViewGroup parent) {
      if (item.getTitle() != null) {
          title.setVisibility(VISIBLE);
          title.setText(item.getTitle());
          title.setText(tvLocation);
  
          System.out.println("222222222");
      } else {
          title.setText("");
          title.setVisibility(GONE);
          System.out.println("111222222");
      }
  }
  
  private class LimitLinearLayout extends LinearLayout {
  
      private static final int MAX_WIDTH_DP = 280;
  
      final float SCALE = getContext().getResources().getDisplayMetrics().density;
  
      public LimitLinearLayout(Context context) {
          super(context);
          System.out.println("33333333");
      }
  
      public LimitLinearLayout(Context context, AttributeSet attrs) {
          super(context, attrs);
          System.out.println("444444");
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int mode = MeasureSpec.getMode(widthMeasureSpec);
          int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
          int adjustedMaxWidth = (int)(MAX_WIDTH_DP * SCALE + 0.5f);
          int adjustedWidth = Math.min(measuredWidth, adjustedMaxWidth);
          int adjustedWidthMeasureSpec = MeasureSpec.makeMeasureSpec(adjustedWidth, mode);
          System.out.println("555555555");
          super.onMeasure(adjustedWidthMeasureSpec, heightMeasureSpec);
      }
  }
  
  }
  </code></pre>
  
  <p>This is balloon_overlay.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/balloon_main_layout"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/balloon_overlay_bg_selector"
  android:minWidth="200dip"
  android:orientation="horizontal"
  android:paddingBottom="25dip"
  android:paddingLeft="10dip"
  android:paddingRight="0dip"
  android:paddingTop="0dip" &gt;
  
  &lt;LinearLayout
      android:id="@+id/balloon_inner_layout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="6dip"
      android:layout_weight="1" &gt;
  
      &lt;LinearLayout
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:gravity="center_vertical"
          android:minHeight="40dip"
          android:orientation="vertical" &gt;
  
          &lt;TextView
              android:id="@+id/balloon_item_title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="@android:color/primary_text_light"
              android:textSize="@string/txtsize"
              android:text="" /&gt;
  
      &lt;/LinearLayout&gt;
      &lt;ImageView
          android:id="@+id/balloon_disclosure"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_gravity="center_vertical"
          android:src="@drawable/balloon_disclosure"
          android:visibility="gone" /&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;ImageView
      android:id="@+id/balloon_close"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingBottom="10dip"
      android:paddingLeft="10dip"
      android:paddingRight="5dip"
      android:paddingTop="5dip"
      android:src="@drawable/balloon_overlay_close" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>