views:

31

answers:

1

I am creating an extension of ItemizedOverlay. When a user taps a pin on the map (onTap) I want to display a RelativeLayout, which is included in the same .xml file as the map. When the RelativeLayout is visable, it covers the map.

Since this view is the context for the main class, I do not know how to access the view (DetailLayout) from within the onTap() call.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
android:id="@+id/mainlayout"    
android:orientation="vertical"    
android:layout_width="fill_parent"    
android:layout_height="fill_parent" >

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="MY KEY HERE"
    />    



    <RelativeLayout 
        android:id="@+id/DetailLayout" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"  
        android:gravity="left"
        xmlns:android="http://schemas.android.com/apk/res/android"&gt;
            <LinearLayout
                android:id="@+id/DetailCloseButtonLayout"
                android:layout_width="fill_parent" 
                android:layout_height="36dp" 
                android:gravity="center_vertical|right"
                xmlns:android="http://schemas.android.com/apk/res/android"&gt;
                <Button       
                    android:id="@+id/DetailCloseButton"     
                    android:background="@drawable/close"  
                    android:layout_width="15dp"        
                    android:layout_height="15dp"
                    android:layout_marginRight="10dp" 
                    android:gravity="center_vertical">
                </Button>
            </LinearLayout>
            <TextView 
                android:text="Detail Here. Detail Here." 
                android:id="@+id/DetailTextView" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_below="@id/DetailCloseButtonLayout">
            </TextView>

    </RelativeLayout>       

A: 

If your ItemizedOverlay is an inner class of your MapActivity, just call findViewById(). Here is a sample project from one of my books showing the sort of thing you are trying to do.

CommonsWare
At the moment, I do not have ItemizedOverlay as an inner class of MapActivty... I could move things around, but will see what else I can accomplish. Right now I am able to read the default TextView text via a Log ("Detail Here. Detail Here."), but I am not able to get the view to display on the screen, as it says "addView" is not recognized within ItemizedOverlay.
Chris
@Chris: "At the moment, I do not have ItemizedOverlay as an inner class of MapActivty" -- you can also pass the `MapActivity` as a constructor parameter of your `ItemizedOverlay`. " but I am not able to get the view to display on the screen, as it says "addView" is not recognized within ItemizedOverlay." -- correct. You do not want to add it to the overlay. You want to add it to whatever you provided to `setContentView()` in your `MapActivity`. Or, have it be there all the time, and toggle it between visible and gone as needed.
CommonsWare