In method onCreate i have button:
connection.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
{
GoogleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle)
{
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location location = LocationServices.FusedLocationApi.getLastLocation(GoogleApiClient);
if (location == null)
{
LocationServices.FusedLocationApi.requestLocationUpdates(GoogleApiClient, LocationRequest, (LocationListener) this);
}
button.setEnabled(false/true);
Hiding is done using View.setVisibility(int)
- options are View.GONE
(completely hides the View, other Views fill its space); View.INVISIBLE
(hides the View but it still occupies the layout space); View.VISIBLE
(shows the View, again occupying the space).
So as people commented before:
if (location == null) {
myButton.setVisibility(View.GONE);
} else {
myButton.setVisibility(View.VISIBLE);
}