Reputation: 317
I'm a beginner in Java. The question might be silly, but please help! I've created tvlat and tvlong of the type TextView as global objects.
public TextView tvlat;
public TextView tvlong;
When I use them in the following code:
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = "Current location : " +
"Lattitude = " + loc.getLatitude() +
"Longitude = " + loc.getLongitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
tvlat.setText(“”+loc.getLatitude());
tvlong.setText(“”+loc.getLongitude());
It says setText(char sequence) in the type TextView is not applicable for the arguments(double) for the code:
tvlat.setText(“”+loc.getLatitude());
tvlong.setText(“”+loc.getLongitude());
Obviously, it happens because tvlat and loc are of two different types. Can anyone suggest me the right way of casting the above statement or resolving the above problem? Thanks for your patience!
Upvotes: 1
Views: 5318
Reputation: 132972
use
tvlat.setText(Double.toString(loc.getLatitude()));
tvlong.setText(Double.toString(loc.getLongitude()));
to get String representation of Double
Upvotes: 1
Reputation: 36449
The quote formatting is odd, it differs from "
. You can try:
tvlat.setText(String.valueOf (loc.getLatitude()));
tvlong.setText(String.valueOf(loc.getLongitude()));
Upvotes: 3