Android Get User Current Location using LocationListener inside a Fragment
<p>I am currently doing a project where the app will get the user's current location and display it on the textview all happening inside a fragment. I don't get any errors but for some reason it doesnt work..</p>

<p>Here is some part of my code.
All permissions in  the manifest and imports are all good..</p>

<p>Another Strange thing is my app doesnt display anything in my logcat when i click the button.</p>

<p>Note: all codes are inside a fragment</p>

<p>Hope someone can give me a hint or two thanks!</p>

<pre><code>import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
private LocationManager locationManager;
private LocationListener listener;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View myinflate = inflater.inflate(R.layout.fragment_home, container, false);
    final TextView cords = (TextView) myinflate.findViewById(R.id.welcome);
    final Button butt = (Button) myinflate.findViewById(R.id.button1);

    locationManager = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
    listener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            cords.setText(location.getLatitude() +" "+location.getLongitude());
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

        @Override
        public void onProviderDisabled(String provider) {

        }
    };

    butt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

                return;
            }else {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
            }
        }
    });

    return myinflate;
}
</code></pre>