Using java Syntax Highlighting
- import android.content.Context;
- import android.util.AttributeSet;
- import android.view.MotionEvent;
- import android.widget.TextView;
- import com.google.android.maps.GeoPoint;
- import com.google.android.maps.MapView;
- public class PointSelectionView extends MapView{
- float[] coords = new float[2];
- public PointSelectionView(Context context, String apiKey) {
- super(context, apiKey);
- }
- public PointSelectionView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public boolean onTouchEvent(MotionEvent me) {
- // TextView tv = (TextView)findViewById(R.id.point);
- // tv.setText(getGeoLocation().toString());
- //
- // return super.onTouchEvent(me);
- coords[0] = me.getX();
- coords[1] = me.getY();
- return super.onTouchEvent(me);
- }
- public GeoPoint getGeoLocation() {
- GeoPoint p = null;
- p = getProjection().fromPixels((int)(coords[0] * 1E6), (int)(coords[1] * 1E6));
- return p;
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
It looks like it should work and everything seems to be working fine. But I add an OnClick Listener in my Activity Class that calls getGeoLocation and assigns assigns it to the text view, but I am not seeing the text view change.
Here is the main Activity:
Using java Syntax Highlighting
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.Animation;
- import android.view.animation.ScaleAnimation;
- import android.widget.Button;
- import android.widget.TextView;
- import com.google.android.maps.GeoPoint;
- import com.google.android.maps.MapActivity;
- public class LocationsSetup extends MapActivity {
- private PointSelectionView map;
- GeoPoint lastPoint;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- map = (PointSelectionView)findViewById(R.id.mapview);
- configButtons();
- }
- protected boolean isRouteDisplayed() {
- return false;
- }
- public void configButtons() {
- final Animation grow = new ScaleAnimation(
- 1.0f, 2.0f,
- 1.0f, 2.0f, 25, 25
- );
- grow.setDuration(500);
- final Animation shrink = new ScaleAnimation(
- 1.0f, .5f,
- 1.0f, .5f, 25, 25
- );
- shrink.setDuration(500);
- final Button in = (Button)findViewById(R.id.zoomin_button);
- in.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- map.getController().zoomIn();
- in.startAnimation(grow);
- }
- });
- final Button out = (Button)findViewById(R.id.zoomout_button);
- out.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- map.getController().zoomOut();
- out.startAnimation(shrink);
- }
- });
- map.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- lastPoint = map.getGeoLocation();
- TextView tv = (TextView)findViewById(R.id.point);
- tv.setText(lastPoint.toString());
- tv.invalidate();
- tv.refreshDrawableState();
- }
- });
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Finally, just for completeness, I have also included my xml file. Please let me know if you have any advice as to why I am not seeing the change. Thanks!
Using xml Syntax Highlighting
- <?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.projects.rnt.PointSelectionView
- android:id="@+id/mapview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:clickable="true"
- android:apiKey="@string/key"
- />
- <Button android:id="@+id/zoomin_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/button_background"
- android:layout_alignParentBottom="true"
- android:layout_marginLeft="10px"
- android:layout_marginRight="10px"
- android:textSize="15pt"
- android:textColor="#FFFFFF"
- android:text="+" />
- <Button android:id="@+id/zoomout_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/button_background"
- android:layout_alignParentBottom="true"
- android:textSize="15pt"
- android:textColor="#FFFFFF"
- android:layout_toRightOf="@id/zoomin_button"
- android:text="-" />
- <TextView android:id="@+id/point"
- android:layout_alignParentBottom="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="#FFFFFF"
- android:text="No Point Yet"
- android:layout_toRightOf="@id/zoomout_button"
- />
- </RelativeLayout>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4
EDIT: This probably could have gone in the layout and resource section as well, but hopefully will get help here as well

