Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:35:58+00:00 2026-06-07T20:35:58+00:00

I have recently started working with Android. I don’t have that much experience with

  • 0

I have recently started working with Android. I don’t have that much experience with Android. This is my first time working with Android. I need to divide the screen in two equal half and then perform few tasks.

  1. After dividing the screen in two equal half, In second half (means bottom half) I need to make a Label named Latitude then corresponding to that a Textbox that will show the current latitude values and another label named Longitude and corresponding to that another Textbox and that will show current longitude value.

I started working on this, And I made some progress- Below is my XML file that I am using currently to divide the screen in two equal half.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.8"
        android:background="#000000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#000000" >

        <!-- Latitude Label -->

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Latitude"
            android:textColor="#372c24" />

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="5dip"
            android:singleLine="true" />
        <!-- Longitude Label -->

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Longitude"
            android:textColor="#372c24" />

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:password="true"
            android:singleLine="true" />
    </LinearLayout>

</LinearLayout>

My Question is-

  1. After using the above XML file, I am not able to see my both label and both textbox properly on the Android Screen, Is there anything I am missing here in my XML file?
  2. Secondly, how I can show the current latitude and longitude value in the corresponding textbox.

Any help will be appreciated as I am new to Android world.

Update:- Below is the diagram that I made in a paint, I want something Like that.enter image description here

If you look at the screen, it got divided in two parts, and in the bottom half part, there are two Labels (Latitude and Longitude) and it should be like that, and infront of each label, there will be a textbox that will hold the corresponding latitude and longitude values.

Update Code:- For Current Location-

public class MainActivity extends Activity implements LocationListener {
    private TextView latituteField;
    private TextView longitudeField;
    private LocationManager locationManager;
    private String provider;

    private static final String TAG = "CurrentLocation";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        latituteField = (TextView) findViewById(R.id.lat1);
        longitudeField = (TextView) findViewById(R.id.lat2);

     // Get the location manager
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        // Define the criteria how to select the location provider -> use
        // default
        Criteria criteria = new Criteria();
        provider = locationManager.getBestProvider(criteria, false);
        locationManager.requestLocationUpdates(provider, 0, 0, this);
        Location location = locationManager.getLastKnownLocation(provider);
        onLocationChanged(location);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        locationManager.removeUpdates(this);
    }

    @Override
    public void onLocationChanged(Location location) {
       if (location != null) {
           System.out.println("Provider " + provider + " has been selected.");
           int lat = (int) (location.getLatitude());
           int lng = (int) (location.getLongitude());
           Log.v(TAG, lat+ " "+ lng);
           latituteField.setText(String.valueOf(lat));
           longitudeField.setText(String.valueOf(lng));
       } else {
           latituteField.setText("Provider not available");
           longitudeField.setText("Provider not available");
       }
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }
}

But the below code is not showing any latitude or longitude values on the corresponding text box? ANything wrong I am doing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:35:59+00:00Added an answer on June 7, 2026 at 8:35 pm

    “After using the above XML file, I am not able to see my both label and
    both textbox properly on the Android Screen, Is there anything I am
    missing here in my XML file?”

    It appeared, you may have had your LinearLayout tags messed up.

    See if this is closer to what you are looking for:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@android:color/black" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
    
            <!-- currently empty -->
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal" >
    
                <!-- Latitude Label -->
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Latitude"
                    android:textColor="#372c24" />
    
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="20dip"
                    android:layout_marginTop="5dip"
                    android:layout_weight="0.35"
                    android:singleLine="true"
                    android:text="test1" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal" >
    
                <!-- Longitude Label -->
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Longitude"
                    android:textColor="#372c24" />
    
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dip"
                    android:layout_weight="0.35"
                    android:password="true"
                    android:singleLine="true"
                    android:text="test2" />
            </LinearLayout>
        </LinearLayout>
    
    </LinearLayout>
    

    Picture

    enter image description here


    “Secondly, how I can show the current latitude and longitude value in
    the corresponding textbox.”

    What have you attempted?

    You need to get the current lat/long.
    Then just set the text on the EditText.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started working with Android, And I need to draw a Circle
This is a very elementary I realize, I have recently started working with asp.net
I have recently started working on my master thesis in C that I haven't
I have a project that I have recently started working on seriously but had
I've been a long time user of R and have recently started working with
I have only recently started working with the MVC approach, so I suppose this
I have recently started working on a very large C++ project that, after completing
I recently started working with Eclipse to build Android Applications. I have made a
I have recently started working on a legacy application that has most of its
I have recently started to learn Objective-C and write my tests using OCUnit that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.