在我的程序中,我有一个与 GPS 一起使用的位置列表器来获取用户当前的纬度/经度点。
我想在 GPS 获得坐标的同时实现一个进度对话框。
目前我在 onCreate() 方法中调用progressDialog,然后当我的位置对象不再为空时,我就会取消progressdialog。
可悲的是,目前对话框根本没有显示。
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
***** Call a new progress dialog object when the locationManager is gaining lat/long*****
d = ProgressDialog.show(this, "GPS Posistion", "Gaining GPS posistion...", false, true);
}
private class GPSLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location location) {
if (location != null) {
***** Once lat/long is found, dismiss the progress dialog*****
d.dismiss();
Double latToPass = location.getLatitude();
Double longToPass = location.getLongitude();
locationManager.removeUpdates(locationListener);
locationManager = null;
Intent changesStart = new Intent("com.example.flybaseapp.PassLatLong");
changesStart.putExtra("passedLat", latToPass);
changesStart.putExtra("passedLong", longToPass);
startActivity(changesStart);
}
}