0

LocationListener.onLocationChanged が呼び出されるまで待機メッセージを表示するために、何を実装する必要があるかを誰かが提案できますか?
タイトルのないダイアログを使用してみましたが、問題は次のとおり
です。 1.それを作成するとsetCancelable(false)、ユーザーは戻るボタンを押すことさえできなくなります。
2. を作成するsetCancelable(true)と、onLocationChanged() の前に出ます。
以下は私のコードです

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Please Wait for GPS Signals...").setCancelable(false);
mLocationWaitDialog = builder.create();
mLocationWaitDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams layoutParam = mLocationWaitDialog.getWindow().getAttributes();
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

layoutParam.y = -height / 2; // y position
mLocationWaitDialog.show(); 
4

3 に答える 3

1

私はこれを持っています:

OnCreate メソッドで:

if (lastKnownLocation == null) {
        Log.i("Location", "lastKnownLocation es null");
        dialog = ProgressDialog.show(this, "Buscando...", "");
}

ダイアログは上で宣言されており、その ProgressDialog です。

次に、ハンドラーで次のようにします。

handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            Log.i("Location", "Mensaje recibido2");
            if(dialog!=null){

            dialog.dismiss();
            }

            LatLng gpsrc = new LatLng(msg.getData().getDouble("lat"),
                    msg.getData().getDouble("lon"));

            continuar(gpsrc);
        }
    };

私の onLocationChanged メソッド:

public void onLocationChanged(Location location) {

    double nuevalat=location.getLatitude();
    double nuevalon=location.getLongitude();
    origen=new LatLng(nuevalat, nuevalon);
    Bundle bundle=new Bundle();
    bundle.putDouble("lat", origen.latitude);
    bundle.putDouble("lon", origen.longitude);
    Message mescoords = new Message();
    mescoords.setData(bundle);

    try {
        handler.sendMessage(mescoords);
    } catch (Exception e) {
        e.printStackTrace();
    }



}

このようにして、onLocationChanged メソッドが呼び出されると、ProgressDialog を閉じるメッセージが送信されます。ProgressDialog でユーザーが戻ることができるかどうか試してみてください。よくわかりません。

于 2013-05-17T11:31:31.170 に答える
0
ProgressDialog pd = new ProgressDialog(activity);
pd.setMessage("Loading.. Please wait");
pd.show();

onLocationChanged() 内で停止します

pd.dismiss();
于 2013-05-17T11:20:40.660 に答える
0

一定時間後にキャンセル可能をtrueに設定するタイムアウトタイマーを設定してみます。これにより、GPS が見つからない場合にユーザーをループに閉じ込めずに、すぐに消えてしまうという問題が解決されます。

于 2013-05-17T11:21:45.363 に答える