【问题标题】:show Progress Dialog in OnLocationChanged在 OnLocationChanged 中显示进度对话框
【发布时间】:2012-07-11 04:24:54
【问题描述】:

我知道有成千上万个这样的问题。但我找不到我的解释。

我使用 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 方法中声明或显示对话框,它永远不会显示。有人吗? 为什么它会关闭它但不能显示它?

【问题讨论】:

    标签: android progressdialog


    【解决方案1】:

    ProgressDialog 中传递LocationListener 类的Context

    【讨论】:

    • 好的。在 AsyncTask 中传递 StoresActivity.this 上下文。
    【解决方案2】:

    检查此代码对我来说工作正常

    公共类LocationFinderActivity扩展Activity实现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
    
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多