vendredi 2 septembre 2016

android pass variable from one override to another

I am working on this android wearable app for my own use and am stuck on how to pass a variable from within a if statement within a override function to another..

@Override
protected void onResume() {
    super.onResume();
    String myYards = "";
    Bundle extras = getIntent().getExtras();
    curhole = extras.getInt("hole");
    if(curhole == 1){
        myYards = "325";
        double lat2 = 39.657479;
        double lon2 = -121.778788;
    }
    if(curhole == 2){
        myYards = "191";
        double lat2 = 39.255478;
        double lon2 = -121.125547;
    }
    TextView holeyard = (TextView) findViewById(R.id.holeYard);
    holeyard.setText(String.valueOf(myYards + " yards"));

    if(googleApiClient.isConnected()){
        requestLocationUpdates();
    }

}

@Override
public void onLocationChanged(Location location) {

    myLatitude = location.getLatitude();
    myLongitude = location.getLongitude();

    Location loc1 = new Location("");
    loc1.setLatitude(myLatitude);
    loc1.setLongitude(myLongitude);
    Location loc2 = new Location("");
    loc2.setLatitude(lat2);
    loc2.setLongitude(lon2);
    float distanceInMeters = loc1.distanceTo(loc2);
    int myDist = (int) (distanceInMeters * 1.0936);
    TextView latView = (TextView) findViewById(R.id.yardage);
    latView.setText(String.valueOf(myDist));
}

I would like to change the gps coordinates based on the hole number within the if statements in the onStart function and pass them to the onLocationChanged function, is this possible? Or am I just going about this wrong as I am new to android..

Thanks!

Aucun commentaire:

Enregistrer un commentaire