Android内部类(LocationListener)从不触发

时间:2013-03-25 00:21:14

标签: android inner-classes locationlistener

我正在使用此代码获取Android设备的GPS坐标。 LocationListener永远不会触发,我不知道为什么。任何建议,将不胜感激。

public class MyClass extends ListActivity {

    private LocationManager locmgr = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylayout);
        // Start the location manager
        locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    } // onCreate

    @Override
    public void onResume() {
        super.onResume();
        // grab the location manager service
        locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                onLocationChange);
    } // onResume

    // Start a location listener
    LocationListener onLocationChange = new LocationListener() {

        public void onLocationChanged(Location loc) {
            // This never fires
            Toast.makeText(getApplicationContext(), "Test",
                    Toast.LENGTH_LONG).show();
        }
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status,
                Bundle extras) {}
    };
} // end MyClass

0 个答案:

没有答案