views:

37

answers:

2

I need to input latitude and longitude separately in 2 EditTexts and diplay 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>
+2  A: 

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

PM - Paresh Mayani
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
Maxood
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.
Maxood
@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.
PM - Paresh Mayani
@Maxood and ya add the "fill_parent" instead of "wrap_content" inside the first LinearLayout so that it accommodates as according to the screen
PM - Paresh Mayani
A: 

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>
Maxood