2012-07-11 120 views
0

我知道有成千上万像这样的问题。但我找不到解释。显示OnLocationChanged中的进度对话框

我使用onLocationChanged方法来更新用户在mapView上的位置。一切安好;我在onCreate方法中显示一个ProgressDialog,并在OnlocationChanged结束时关闭ProgressDialog,它可以工作。

问题是当我在onLocationChanged方法内创建并显示进度对话框时。不知何故,它不起作用。我认为这是因为该方法在不同的线程上运行。

但我的问题是,如果onLocationChanged方法运行在不同的线程上,为什么它让我忽略对话框但不创建一个新的?

这里是我的类的一部分:

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tiendas); 
    mapView = (MapView) findViewById(R.id.mapview); 
    mapView.setBuiltInZoomControls(true); 
    mapView.setSatellite(false); 

    ProgressDialog dialog = ProgressDialog.show(StoresActivity.this, "", 
    "Getting your location", true, true); 


public void onLocationChanged(Location location) { 
      // TODO Auto-generated method stub 

      /////if i show or initialize the dialog here, doesn't work! 

      updateMap(location) // this function calls asynctask 
               // for an HTTPrequest 
    dialog.dismiss(); 


     } 

}

该代码工作,正确关闭对话框,但如果我宣布或显示onLocationChanged方法中的对话框,它永远不会显示。任何人? 它为什么忽略它但不能显示它?

+0

你可以发布您的代码 – 2012-07-11 04:33:15

+0

它就在那里,谢谢! – 2012-07-11 23:06:27

回答

0

ProgressDialog中通过LocationListener类的Context

+0

你怎么能这样做?有我的代码。有任何想法吗? – 2012-07-11 22:45:38

+0

好的。在AsyncTask中传递StoresActivity.this上下文。 – 2012-07-15 09:33:40

-1

检查这个代码其工作正常,我

公共类LocationFinderActivity扩展活动实现LocationListener的{

LocationManager locationManager = null; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_location_finder); 

    Log.i("inside","oncreate"); 
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0,this); 


} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_location_finder, menu); 
    return true; 
} 

@Override 
public void onLocationChanged(Location location) { 

    Log.i("inside","onlocationchange"); 
    ProgressDialog dialog = ProgressDialog.show(LocationFinderActivity.this, "", 
      "Getting your location", true, true); 
} 

@Override 
public void onProviderDisabled(String provider) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
    // TODO Auto-generated method stub 

} 

}