I have a question about android programming. I have a MainActivity class and class that implements LocationListner. I want to change some UI elements from onLocationChanged method from this second class but I have no idea how things like this should be done.
Here is my mainActivity:
public class MainActivity extends AppCompatActivity {
private LocationGPS gps;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enableGPS();
initGuiElements();
}
private void enableGPS()
{
gps = new LocationGPS(this);
}
private void initGuiElements()
{
text = (TextView) findViewById(R.id.textTop);
text.setText("nothing yet");
}
}
Here is my class for location.
public class LocationGPS implements LocationListener {
private Activity mainActivity;
private LocationManager locationManager;
public LocationGPS(Activity activity)
{
this.mainActivity = activity;
locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
//here I want to set text for TextView element
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}