android字符串換行不正常的問題

很多代碼感覺沒問題,可寫到到代碼裏就問題就出來了."/n"居然換行不成功!問題代碼如下:
// /聲明定位回調監聽器
        AMapLocationListener mLocationListener = new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                if (aMapLocation != null) {
                    if (aMapLocation.getErrorCode() == 0) {
                        mTvicon.setText(("獲取當前定位結果來源:"+aMapLocation.getLocationType()
                                +"/n獲取緯度:"+aMapLocation.getLatitude()+
                        "/n獲取經度:"+aMapLocation.getLongitude()+
                        "/n獲取精度信息:"+aMapLocation.getAccuracy()+
                        "/n地址;"+aMapLocation.getAddress()+
                        "/n國家信息:"+aMapLocation.getCountry()+
                        "/n省信息"+aMapLocation.getProvince()+
                        "/n城市信息"+aMapLocation.getCity()));
                    } else {
                        //定位失敗時,可通過ErrCode(錯誤碼)信息來確定失敗的原因,errInfo是錯誤信息,詳見錯誤碼錶。
                        Log.e("AmapError","location Error, ErrCode:" +
                                aMapLocation.getErrorCode() + ", errInfo:" +
                                aMapLocation.getErrorInfo());
                        ToastUtil.ShortToast("123456");
                    }
                }
            }
        };

輸出的結果是不換行的"/n"也沒轉換

正確代碼如下:

 // /聲明定位回調監聽器
        AMapLocationListener mLocationListener = new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                if (aMapLocation != null) {
                    if (aMapLocation.getErrorCode() == 0) {
//                        mTvicon.setText(("獲取當前定位結果來源:"+aMapLocation.getLocationType()
//                                +"/n獲取緯度:"+aMapLocation.getLatitude()+
//                        "/n獲取經度:"+aMapLocation.getLongitude()+
//                        "/n獲取精度信息:"+aMapLocation.getAccuracy()+
//                        "/n地址;"+aMapLocation.getAddress()+
//                        "/n國家信息:"+aMapLocation.getCountry()+
//                        "/n省信息"+aMapLocation.getProvince()+
//                        "/n城市信息"+aMapLocation.getCity()));
                        StringBuffer sb = new StringBuffer(256);
                        sb.append("獲取當前定位結果來源:");
                        sb.append(aMapLocation.getLocationType());
                        sb.append("\n獲取緯度:");
                        sb.append(aMapLocation.getLatitude());
                        sb.append("\n獲取經度:");
                        sb.append(aMapLocation.getLongitude());
                        sb.append("\n獲取精度信息:");
                        sb.append(aMapLocation.getAccuracy());
                        sb.append("\n地址;");
                        sb.append(aMapLocation.getAddress());
                        sb.append("\n國家信息:");
                        sb.append(aMapLocation.getCountry());
                        sb.append("\n省信息");
                        sb.append(aMapLocation.getProvince());
                        mTvicon.setText(sb.toString());
                    } else {
                        //定位失敗時,可通過ErrCode(錯誤碼)信息來確定失敗的原因,errInfo是錯誤信息,詳見錯誤碼錶。
                        Log.e("AmapError","location Error, ErrCode:" +
                                aMapLocation.getErrorCode() + ", errInfo:" +
                                aMapLocation.getErrorInfo());
                        ToastUtil.ShortToast("123456");
                    }
                }
            }
        };
這樣就上線自動換行了!!
如果解決了你 的問題給個贊吧^@^!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章