Focus: MapView(RelativL.) and EditText(LinearL.)


Last Updated:

  1. puk

    puk New Member This Topic's Starter

    Joined:
    Feb 27, 2009
    Messages:
    3
    Likes Received:
    0
    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:
    Code (Text):
    1.  
    2. <LinearLayout>
    3.  
    4.  <LinearLayout-x>
    5.   <EditText (search-String) />
    6.   <Button (send-Button) />
    7.  </LinearLayout-x>
    8.  
    9.  <RelativLayout-y>
    10.   <MapView />
    11.   <LinearLayout (zoomelements) />
    12.  </RelativLayout-y>
    13.  
    14. </LinearLayout>
    15.  
    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
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:id="@+id/main"
    4.     android:orientation="vertical"
    5.     android:layout_width="fill_parent"
    6.     android:layout_height="fill_parent">
    7.    
    8.     <LinearLayout android:orientation="horizontal"
    9.         android:layout_width="fill_parent"
    10.         android:layout_height="wrap_content" >
    11.        
    12.         <EditText android:id="@+id/field_search"
    13.             android:layout_width="fill_parent"
    14.             android:layout_height="wrap_content"
    15.             android:layout_weight="1"
    16.               android:scrollbars="vertical"
    17.               android:lines="1" />
    18.         <Button android:id="@+id/search"
    19.             android:text="search"
    20.             android:layout_width="wrap_content"
    21.             android:layout_height="fill_parent" />
    22.     </LinearLayout>
    23.    
    24.     <RelativeLayout android:orientation="vertical"
    25.         android:layout_width="fill_parent"
    26.         android:layout_height="fill_parent"
    27.         android:layout_weight="1"
    28.         android:focusable="true"
    29.         android:focusableInTouchMode="true">
    30.        
    31.         <!-- for key:http://code.google.com/intl/de-DE/android/toolbox/apis/mapkey.html#getdebugfingerprint  -->
    32.         <com.google.android.maps.MapView
    33.             android:id="@+id/map"
    34.             android:layout_width="fill_parent"
    35.             android:layout_height="fill_parent"
    36.             android:enabled="true"
    37.             android:clickable="true"
    38.             android:apiKey="0CMIRxnrxbszEq1rT5ApxgzjYGcwtStf-4Vagfg" />
    39.        
    40.         <LinearLayout
    41.             android:id="@+id/zoomelements"
    42.             android:layout_width="wrap_content"
    43.             android:layout_height="wrap_content"
    44.             android:layout_alignBottom="@id/map"
    45.             android:layout_centerHorizontal="true"
    46.         />
    47.     </RelativeLayout>    
    48. </LinearLayout>
    mappppper.java
    Code (Text):
    1. package com.android.mapper;
    2.  
    3. import java.util.List;
    4.  
    5. import android.graphics.drawable.Drawable;
    6. import android.os.Bundle;
    7. import android.view.KeyEvent;
    8. import android.widget.LinearLayout;
    9. import android.widget.ZoomControls;
    10.  
    11. import com.google.android.maps.GeoPoint;
    12. import com.google.android.maps.MapActivity;
    13. import com.google.android.maps.MapController;
    14. import com.google.android.maps.MapView;
    15. import com.google.android.maps.Overlay;
    16. import com.google.android.maps.OverlayItem;
    17.  
    18. public class mappppper extends MapActivity {
    19.    
    20.      LinearLayout linearLayout;
    21.     private MapView map;
    22.     private MapController mc;
    23.      private ZoomControls mz;
    24.     private static int zoomValue = 5;
    25.    
    26.     List<Overlay> mapOverlays;
    27.     Drawable drawable;
    28.     HelloItemizedOverlay itemizedoverlay;
    29.    
    30.     /** Called when the activity is first created. */
    31.     @Override
    32.     public void onCreate(Bundle savedInstanceState) {
    33.         super.onCreate(savedInstanceState);
    34.         setContentView(R.layout.main);
    35.          linearLayout = (LinearLayout) findViewById(R.id.zoomelements);
    36.         map = (MapView) findViewById(R.id.map);
    37.         mc = map.getController();
    38.          mz = (ZoomControls) map.getZoomControls();
    39.         mc.setZoom(zoomValue);
    40.          linearLayout.addView(mz);
    41.          
    42.          mapOverlays = map.getOverlays();
    43.          drawable = this.getResources().getDrawable(R.drawable.fm);
    44.          itemizedoverlay = new HelloItemizedOverlay(drawable);
    45.          
    46.          GeoPoint point = new GeoPoint(52518333, 13408333);
    47.          OverlayItem overlitem = new OverlayItem(point, "", "");
    48.          
    49.          itemizedoverlay.addOverlay(overlitem);
    50.          mapOverlays.add(itemizedoverlay);
    51.     }
    52.  
    53.     @Override  
    54.     public boolean dispatchKeyEvent(KeyEvent event) {  
    55.         if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) {  
    56.             zoomValue = zoomValue + 1;  
    57.             mc.setZoom(zoomValue);  
    58.         } else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {  
    59.             zoomValue = zoomValue - 1;  
    60.             mc.setZoom(zoomValue);  
    61.         } else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {  
    62.             map.setSatellite(false);  
    63.         } else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {  
    64.             map.setSatellite(true);  
    65.         }  
    66.         return super.dispatchKeyEvent(event);  
    67.     }
    68.    
    69.     @Override
    70.     protected boolean isRouteDisplayed() {
    71.         // TODO Auto-generated method stub
    72.         return false;
    73.     }
    74. }
    My code is based on the android tutorial:
    http://developer.android.com/guide/tutorials/views/hello-mapview.html

    thank you.
     

    Advertisement
  2. AndroidDeveloper

    AndroidDeveloper Member

    Joined:
    Mar 9, 2009
    Messages:
    7
    Likes Received:
    0

Share This Page

Loading...