您的位置:首页 > 移动开发 > Android开发

android字符串换行不正常的问题

2017-05-24 10:15 246 查看
很多代码感觉没问题,可写到到代码里就问题就出来了."/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");
}
}
}
};这样就上线自动换行了!!

如果解决了你 的问题给个赞吧^@^!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息