0

I am having difficulty in showing a specific item on a map. When user clicks a point I want to place an object with a counter on top. I was thinking in using a text view and converting it in a drawable, using this method but it does not work. What i tried looks like this :
xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout ... >
    <TextView
        android:id="@+id/object"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableBottom="@drawable/car"
        android:text="Human 1,2..." /> <!-- Here should be the counter modified programatically -->
</LinearLayout>

code:

    public boolean onTouchEvent(MotionEvent e, MapView m) {
    ....
        CustomPinPoint custom = new CustomPinPoint(getHuman(), Main.this);
    }
    private Drawable getHuman() {
            Bitmap snapshot = null;
            Drawable drawable = null;
            LayoutInflater li = Main.this.getLayoutInflater();
            View view = li.inflate(R.layout.human, null); //human is the layout
            view.setDrawingCacheEnabled(true);
            view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
            try {
                snapshot = Bitmap
                        .createBitmap(view.getDrawingCache());
                drawable = new BitmapDrawable(snapshot);
            } finally {
                view.setDrawingCacheEnabled(false);
            }
            return drawable;

        }

Currently, i get null pointer at Bitmap.createBitmap(view.getDrawingCache());. Tried it with dimensions, still no success. Can someone tell me what am I doing wrong? Or if there is another approach to getting drawable from text view?
Thanks in advance, Cosmin.

Community
  • 1
  • 1
cosmincalistru
  • 1,283
  • 9
  • 20

1 Answers1

0

Your question is not very clear...

If you want to place an object always in the same place and you want to show it independently from where the user touched the map, the add the oject to the same layout where you have the map view as I show in this answer Animated Menu Buttons on top of MapView and then make it visible/invisible and change the counter as needed.

If you want someting else, add some more information to your question.

good luck.

Community
  • 1
  • 1
Luis
  • 11,978
  • 3
  • 27
  • 35