0

我想知道是否有人可以告诉我为什么在下面的代码中,mLat 和 mLon 给我错误,说符号无法解析?

我很确定我已经在私有类 GPSCoords 中正确定义了它们:

private class GPSCoords {
    float mLat, mLon;

    GPSCoords(float lat, float lon) {
        mLat = lat;
        mLon = lon;

    }
}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case PLACE_DIALOG_ID:

            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View dialogLayout = layoutInflater.inflate(R.layout.fav_place_dialog, (ViewGroup) findViewById(R.id.root));

            final TextView placeCoordinates = (TextView) dialogLayout.findViewById(R.id.TextView_FavPlaceCoords_Info);
            final EditText placeName = (EditText) dialogLayout.findViewById(R.id.EditText_FavPlaceName);
            placeName.setOnKeyListener(new View.OnKeyListener() {

                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {

                        String strPlaceName = placeName.getText().toString();
                        if ((strPlaceName != null) && (strPlaceName.length() > 0)) {
                            // Try to resolve string into GPS coords
                            resolveLocation(strPlaceName);

                            Editor editor = mGameSettings.edit();
                            editor.putString(GAME_PREFERENCES_FAV_PLACE_NAME, placeName.getText().toString());
                            editor.putFloat(GAME_PREFERENCES_FAV_PLACE_LONG, mFavPlaceCoords.mLon);
                            editor.putFloat(GAME_PREFERENCES_FAV_PLACE_LAT, mFavPlaceCoords.mLat);
                            editor.commit();

                            placeCoordinates.setText(formatCoordinates(mFavPlaceCoords.mLat, mFavPlaceCoords.mLon));
                            return true;
                        }
                    }
                    return false;
                }
            });

我有点难过。

谢谢

编辑:显示我定义 mFavPlaceCoords 的位置。另外,我将 mFavPlaceCoords 作为私有对象:

if (mGameSettings.contains(GAME_PREFERENCES_FAV_PLACE_NAME)) {

                // Retrieve favorite place from preferences
                strFavPlaceName = mGameSettings.getString(GAME_PREFERENCES_FAV_PLACE_NAME, "");
                mFavPlaceCoords = new GPSCoords(mGameSettings.getFloat(GAME_PREFERENCES_FAV_PLACE_LAT, 0), mGameSettings.getFloat(GAME_PREFERENCES_FAV_PLACE_LONG, 0));

            } else {

                // No favorite place set, set coords to current location
                strFavPlaceName = getResources().getString(R.string.settings_favplace_currentlocation); // We do not name this place ("here"), but use it as a map point. User can supply the name if
                // they like
                calculateCurrentCoordinates();

            }
4

0 回答 0