0

私はこのような質問が何千もあることを知っています。しかし、私は私の説明を見つけることができません。

onLocationChangedメソッドを使用して、mapView上のユーザーの場所を更新します。すべて順調; onCreateメソッドにProgressDialogを表示し、OnlocationChangedの最後でそれを閉じれば機能します。

問題は、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メソッド内でダイアログを宣言または表示すると、表示されません。誰か?なぜそれを却下するのに見せられないのですか?

4

2 に答える 2

0

クラスのContextをに渡します。LocationListenerProgressDialog

于 2012-07-11T04:56:18.677 に答える
-1

このコードをチェックしてください。

public class LocationFinderActivity extends Activityimplements 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

}

}

于 2012-07-12T03:55:24.117 に答える