2012-07-11 116 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 

} 

}