Callout View and Text Views (Android API)

5086
1
12-09-2011 03:20 PM
AndrewDickel
New Contributor
I have a little program and im trying to populate a callout with feature data, I have a custom callout view style and a custom view that I'm inserting into my callout.  In the view, there are 6 TextViews and 3 of them are labels and 3 I want to be labeled with data from java.  I use view1.setText("MyText")  after getting the Ids from the callout view. 

The problem is none of the text from java is showing up on the callout.   The static text labels show up fine and my calloutViewStyle works fine as well.  I'm not sure what to do and it'd be great if I could get this working soon. 

Also, Is there some way to populate a call out with a "Graphic" object and its attribute names/table?

Heres the custom view I am inserting into my callout


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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/beginatStr"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textSize="8sp" >
</TextView>

        <TextView
            android:id="@+id/calloutBeginsAt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView1"
            android:layout_toRightOf="@+id/textView1"
            android:text="TextView"
            android:textColor="#000000"
            android:textSize="8sp" >
</TextView>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="16dp"
            android:text="@string/calloutEndsAt"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textSize="8sp" >
</TextView>

        <TextView
            android:id="@+id/calloutEndsAt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView2"
            android:layout_alignLeft="@+id/calloutBeginsAt"
            android:text="TextView"
            android:textColor="#000000"
            android:textSize="8sp" >
</TextView>

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView2"
            android:layout_marginTop="18dp"
            android:text="@string/calloutLoc"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textSize="8sp" >
</TextView>

        <TextView
            android:id="@+id/calloutLoc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView4"
            android:layout_alignLeft="@+id/calloutEndsAt"
            android:text="TextView"
            android:textColor="#000000"
            android:textSize="8sp" >
</TextView>
    </RelativeLayout>


Here is the java portion where I am setting up the values.  Thanks for all the help in advance!

 
Callout callout = map.getCallout();  
  callout.setCoordinates((Point) event.getGeometry());
  callout.setTitle(event.getName()); 
  
  View calloutView = inflater.inflate(R.layout.callout, null);
  
  //Access the internal Textviews insdie the calloutView.
  TextView begins = (TextView) calloutView.findViewById(R.id.calloutBeginsAt);
  TextView ends = (TextView) calloutView.findViewById(R.id.calloutEndsAt);
  TextView loc = (TextView) calloutView.findViewById(R.id.calloutLoc); 
  
  //Set Up values  
  begins.setText(event.getNextOccurance().getBegin().getDay() + ", " + event.getNextOccurance().getBegin().getHours()
    + ":" + event.getNextOccurance().getBegin().getMinutes());  
  
  ends.setText(event.getNextOccurance().getEnd().getDay() + ", " + event.getNextOccurance().getEnd().getHours()
    + ":" + event.getNextOccurance().getEnd().getMinutes());
  
  loc.setText(event.getAddress());  
 
  begins.setEnabled(true);
  ends.setEnabled(true);
  loc.setEnabled(true);

  //Set the content, show the view
  callout.setContent(calloutView);
  callout.show(); 
0 Kudos
1 Reply
StephenQuan
Occasional Contributor
A couple of gotchas that I had to go through to make callouts work for me:


  • callout.setCoordinates() needs to take a Point expressed in your map's coordinate system, not screen units.

  • callout.setStyle(R.xml.calloutstyle) should be used in conjunction with a res/xml/calloutstyle.xml file.

  • callout.refresh() may need to be called.


Where Res/xml/calloutstyle.xml is defined in your resource tree as:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
 <calloutViewStyle
   titleTextColor="#000000"
   titleTextSize="10"
   titleTextStyle="0"
   titleTextTypeFace="0"
   backgroundColor="#ffffff" 
   backgroundAlpha="255"
   frameColor="#000000"
   flat="true"
   anchor="5" />
 </resources>


Here's an example of your callout working in a MapView.onSingleTap:

  final Context ctx = this;
  final LayoutInflater inflater = this.getLayoutInflater();
  map.setOnSingleTapListener(new OnSingleTapListener() {
   private static final long serialVersionUID = 5173550791541184304L;

   public void onSingleTap(float x, float y) {
    Toast.makeText(
     ctx,
     "onSingleTap(" + String.valueOf(x) + " , " + String.valueOf(y) + ")",
     Toast.LENGTH_SHORT
    ).show();
    
    Point screenPoint = new Point(x, y);
    Point mapPoint = map.toMapPoint(screenPoint);
    
    Callout callout = map.getCallout();
    callout.setCoordinates(mapPoint);
    //callout.setCoordinates((Point) event.getGeometry());
    //callout.setTitle(event.getName()); 
    
    View calloutView = inflater.inflate(R.layout.callout, null);
    
    //Access the internal Textviews inside the calloutView.
    TextView begins = (TextView) calloutView.findViewById(R.id.calloutBeginsAt);
    TextView ends = (TextView) calloutView.findViewById(R.id.calloutEndsAt);
    TextView loc = (TextView) calloutView.findViewById(R.id.calloutLoc); 
    
    //Set Up values  
    begins.setText("begins");  
    ends.setText("ends");
    loc.setText("loc");  
   
    begins.setEnabled(true);
    ends.setEnabled(true);
    loc.setEnabled(true);

    //Set the content, show the view
    callout.setContent(calloutView);
    callout.setStyle(R.xml.calloutstyle);
    callout.refresh();
    callout.show();
   }
  } );
0 Kudos