getName() в другую активность

Рейтинг: 0Ответов: 1Опубликовано: 31.03.2015

Привет всем. Помогите пожалуйста, я никак не могу понять, как это сделать. Надо с помощью getName() в GeoPoint вывести имя в ScreenOne в TextView.

Код ScreenOne:

package com.example.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.Arrays;

public class ScreenOne extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen_one);
    }

    GeoPoint currentLocation;

    GeoPoint locations[] = new GeoPoint[] {
        new GeoPoint(55.895859, 37.719324, "Точка1"),
        new GeoPoint(55.881231, 37.636800, "Точка2"),
        new GeoPoint(55.865430, 37.648020, "Точка3")
    };
    GeoPoint nearest = GeoPoint.getNearestLocation(currentLocation, Arrays.asList(locations));

    public void onClick(View view) {
        TextView helloTextView = (TextView)findViewById(R.id.station_name);
        helloTextView.setText(nearest.toString());
    }

}

И код GeoPoint:

package com.example.app;

import android.location.Location;

import java.util.Collection;

public class GeoPoint {

    public final double lat;
    public final double lon;
    private Sting name;

    public GeoPoint(double lat, double lon, String name) {
        this.lat = lat;
        this.lon = lon;
        this.name = name;
    }

    public GeoPoint(Location location) {
        this.lat = location.getLatitude();
        this.lon = location.getLongitude();
    }

    public static GeoPoint getNearestLocation(GeoPoint current, Collection<GeoPoint> locations) {
        GeoPoint res = null;
        float lastDisance = Float.MAX_VALUE;
        float locDistance[] = new float[1];
        for (GeoPoint loc: locations) {
            Location.distanceBetween(current.lat, current.lon, loc.lat, loc.lon, locDistance);
            if (res == null || locDistance[0] < lastDisance) {
                res = loc;
                lastDisance = locDistance[0];
            }
        }
        return res;
    }

    public Sting getName() {
        return name;
    }

}

Ответы

▲ 2Принят
public void onClick(View view) {
    TextView helloTextView = (TextView)findViewById(R.id.station_name);
    helloTextView.setText(nearest.toString());
}

Заменить на

public void onClick(View view) {
    TextView helloTextView = (TextView)findViewById(R.id.station_name);
    helloTextView.setText(nearest.getName());
}