我要做的是在用户单击一个名为 location_Button 的按钮后获取用户的位置,然后显示一个显示有关其位置的一些信息的框。我试过这样:
Button location_Button=(Button) findViewById(R.id.location_button);
location_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Define a listener that responds to location updates
progressDialog = ProgressDialog.show(Settings.this, "", "Loading...");
final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
lat =location.getLatitude();
lon = location.getLongitude();
try{
addresses=(geocoder.getFromLocation(lat, lon, 1));
if (addresses.size() > 0) {
String city = addresses.get(0).getAddressLine(1);
String id = city.substring(0,city.length()-5);
String state1=String.valueOf(id.charAt(id.length()-3));
String state2=String.valueOf(id.charAt(id.length()-2));
String STATE = state1+state2;
locationManager.removeUpdates(this);
progressDialog.dismiss();
//alert dialog is established and displayed here
}
else {
//tv.setText("Oops...");
}
}catch(IOException e){
e.printStackTrace();
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
问题是进度对话框永远不会被解雇。按下按钮时没有进度对话框,它会搜索然后显示该框,而在进度对话框中,它会继续说正在加载并且永远不会被关闭。我的目标是在建立位置后关闭进度对话框,警报对话框也应该弹出但它不是。进度对话框的位置不正确吗?