0

I need to input latitude and longitude separately in 2 EditTexts and display the location at the click of a button. Somehow i'm not able to get the correct layout as i precisely require 2 EditTexts aligned side by side and a button below them.

Here is what i already have:

    <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" />

    <EditText  
        android:layout_width="wrap_content" 
        android:text="@+id/EditText01"      
        android:layout_height="wrap_content" 
        android:id="@+id/edLat" 
        android:layout_toRightOf="@+id/mapView">
    </EditText>
    <EditText 
        android:layout_marginLeft="-237dip"  
        android:layout_marginTop="100dip" 
        android:layout_width="wrap_content" 
        android:text="@+id/EditText01" 
        android:layout_height="wrap_content" 
        android:id="@+id/edLong" 
        android:layout_toRightOf="@+id/mapView">
    </EditText>
    <Button 
        android:layout_marginLeft="-237dip"            
        android:layout_marginTop="200dip" 
        android:layout_width="wrap_content" 
        android:text="Show Location" 
        android:layout_height="wrap_content" 
        android:id="@+id/btnShowLoc"  
        android:layout_toRightOf="@+id/mapView"></Button>

    <com.google.android.maps.MapView 

        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg" />

</LinearLayout>
Yurets
  • 3,999
  • 17
  • 54
  • 74
Muhammad Maqsoodur Rehman
  • 33,681
  • 34
  • 84
  • 124

2 Answers2

2

The below code suits your requirements:

<LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical">

    <LinearLayout android:id="@+id/LinearLayout01" 
                  android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"
                  android:orientation="horizontal">

          <EditText 
            android:layout_width="wrap_content"     
            android:layout_height="wrap_content"    
            android:id="@+id/edLat">
          </EditText>

          <EditText     
            android:layout_width="wrap_content"     
            android:layout_height="wrap_content"    
            android:id="@+id/edLong">
           </EditText>
    </LinearLayout>

    <Button 
        android:layout_width="wrap_content" 
        android:text="Show Location" 
        android:layout_height="wrap_content" 
        android:id="@+id/btnShowLoc">
    </Button>

    <com.google.android.maps.MapView 

        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg"
        />
</LinearLayout>

Note:

you have written the below kind of code:

 <EditText android:layout_marginLeft="-237dip" android:layout_marginTop="100dip" android:layout_width="wrap_content" android:text="@+id/EditText01" android:layout_height="wrap_content" android:id="@+id/edLong" android:layout_toRightOf="@+id/mapView"></EditText>

I would like to tell you that don't give this kind of position to any control because in Android, there are different types of resolutions so it will not look the same design on every Android device.

After seeing your code, i can say you should learn Layouts and code techniques first. Refer Android-sdk pages.

Updated Answer with Images:<29-oct-2010>


I think you forgot to add <uses-library android:name="com.google.android.maps" /> permission in AndroidManifest.xml file, add this permission inside the <application> tag.

Check out the below image, the same above code working for me:

alt text

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • Thanks for your advice! Your code failed to execute There is a fatal error there: 10-29 11:39:27.381: ERROR/AndroidRuntime(304): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apps.samplelayout/com.apps.samplelayout.SampleLayout}: android.view.InflateException: Binary XML file line #34: Error inflating class com.google.android.maps.MapView – Muhammad Maqsoodur Rehman Oct 29 '10 at 05:41
  • I have come up with my own code that works fine and suits my requirement. See me answer and please be critical again. Thanks for your advice. – Muhammad Maqsoodur Rehman Oct 29 '10 at 05:42
  • @Maxood hey maxood, its working fine for me, see the attached image and also i think you may forgot to add uses-service permission in AndroidManifest.xml file. – Paresh Mayani Oct 29 '10 at 06:13
  • 1
    @Maxood and ya add the "fill_parent" instead of "wrap_content" inside the first LinearLayout so that it accommodates as according to the screen – Paresh Mayani Oct 29 '10 at 06:16
  • @Paresh Mayani Yes it is working fine now.Thanks.Have you read my next question on rss feeds? – Muhammad Maqsoodur Rehman Nov 03 '10 at 04:22
  • @Maxood glad about your reply, no i didnt read your next question, give me link – Paresh Mayani Nov 03 '10 at 05:26
  • @Paresh Mayani Here is the link: http://stackoverflow.com/questions/4050766/how-to-get-rss-feeds-android – Muhammad Maqsoodur Rehman Nov 04 '10 at 06:09
0

I tried using a tabular layout here and works fine for my purpose. I'd appreciate if anyone can come up with a better layout and provide me with a valuable suggestion. Thanks

        <EditText 
            android:id="@+id/edLat" 
            android:width="200px" />
    </TableRow> 
    <TableRow>

        <EditText 
            android:id="@+id/edLong" 

            />
    </TableRow>

    <TableRow>
     <Button
        android:id="@+id/btnShowLoc"
        android:layout_width="125px"
        android:layout_height="wrap_content"
        android:text="Show Location"
        android:layout_below="@+id/txtComments"
        android:layout_alignBottom="@+id/mapView"
        />
        </TableRow>

    <TableRow>
         <com.google.android.maps.MapView 

        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg"

        />  
    </TableRow>
     <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        /> 

</TableLayout>
Muhammad Maqsoodur Rehman
  • 33,681
  • 34
  • 84
  • 124