Android的,如何活动现场从LocationListener.onlocationchanged变化()? [英] Android, how to change activity field from LocationListener.onlocationchanged()?
本文介绍了Android的,如何活动现场从LocationListener.onlocationchanged变化()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何从LocationListener.onlocationchanged更改活动场()?我想我必须使用一个处理程序,但不知道怎么办呢,到底...
我的code是这样的:
How do I change an activity field from LocationListener.onlocationchanged() ? I suppose I have to use a handler, but don't know how to do it, exactly... My code is like this:
public class Main extends Activity {
private Double lat, lon;
private LocationManager locationManager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListenerGps = new CurrentLocationGps();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
}
}
public class CurrentLocationGps implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
lat = loc.getLatitude();
lon = loc.getLongitude();
>>>>>>>>---<<<<<<<<< How do I pass this values to Main activity fields?
}
}
}
推荐答案
将主类中CurrentLocationGps类(使它成为一个的内部类),这样你就可以访问主要活动的所有领域。
Place the CurrentLocationGps class inside the Main class (making it an inner class), this way you can access all the fields in Main activity.
这篇关于Android的,如何活动现场从LocationListener.onlocationchanged变化()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文