hello, i'm writing an application wich uses the map with a search-field on top of the map. the main.xml looks like that:
If using the d-pad(up down left right) the two fields (LinearLayout-x and RelativeLayout-y) react both at the same time to the input. That means if scrolling through the text in the Edit Field the map changes the zoom. Because I'm using the d-pad for managing the map. Do i need focus-stuff or does anyone has a better idea for controlling my application?
I tried to play a little bit with the focus options of android, without success
main.xml
mappppper.java
My code is based on the android tutorial:
http://developer.android.com/guide/tutorials/views/hello-mapview.html
thank you.
Code:
<LinearLayout>
<LinearLayout-x>
<EditText (search-String) />
<Button (send-Button) />
</LinearLayout-x>
<RelativLayout-y>
<MapView />
<LinearLayout (zoomelements) />
</RelativLayout-y>
</LinearLayout>
I tried to play a little bit with the focus options of android, without success
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText android:id="@+id/field_search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical"
android:lines="1" />
<Button android:id="@+id/search"
android:text="search"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true">
<!-- for key:http://code.google.com/intl/de-DE/android/toolbox/apis/mapkey.html#getdebugfingerprint -->
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0CMIRxnrxbszEq1rT5ApxgzjYGcwtStf-4Vagfg" />
<LinearLayout
android:id="@+id/zoomelements"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/map"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</LinearLayout>
mappppper.java
Code:
package com.android.mapper;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class mappppper extends MapActivity {
LinearLayout linearLayout;
private MapView map;
private MapController mc;
private ZoomControls mz;
private static int zoomValue = 5;
List<Overlay> mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedoverlay;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.zoomelements);
map = (MapView) findViewById(R.id.map);
mc = map.getController();
mz = (ZoomControls) map.getZoomControls();
mc.setZoom(zoomValue);
linearLayout.addView(mz);
mapOverlays = map.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.fm);
itemizedoverlay = new HelloItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(52518333, 13408333);
OverlayItem overlitem = new OverlayItem(point, "", "");
itemizedoverlay.addOverlay(overlitem);
mapOverlays.add(itemizedoverlay);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) {
zoomValue = zoomValue + 1;
mc.setZoom(zoomValue);
} else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
zoomValue = zoomValue - 1;
mc.setZoom(zoomValue);
} else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
map.setSatellite(false);
} else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
map.setSatellite(true);
}
return super.dispatchKeyEvent(event);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
http://developer.android.com/guide/tutorials/views/hello-mapview.html
thank you.