1. 初次接触append函数
可以用append来为TextView显示文字
值得注意的是,append()与setText()的区别是:
- append()函数将文字添加在已有的TextView内容之后
- setText()是直接将TextView中的内容覆盖
StringBuilder可以多次调用append函数,用法如下
address_tv = (TextView) findViewById(R.id.address);
StringBuilder currentPosition = new StringBuilder();
currentPosition.append("纬度:").append(location.getLatitude()).append("\t");
currentPosition.append("经度:").append(location.getLongitude()).append("\n");
currentPosition.append("省:").append(location.getProvince()).append("\t");
currentPosition.append("市:").append(location.getCity()).append("\t");
currentPosition.append("区:").append(location.getDistrict()).append("\n");
currentPosition.append("街道:").append(location.getStreet()).append("\t");
currentPosition.append("门牌号:").append(location.getStreetNumber());
address_tv.setText(currentPosition);
并最后将其一次性赋值给TextView。
2.(百度地图sdk)经纬度以外城市、街道信息等的显示
若缺少注释所标识的代码,只可获得经纬度,无法获取其余信息,可参考上一段代码
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); // 打开gps
option.setCoorType("bd09ll"); // 设置坐标类型
option.setScanSpan(1000);
option.setIsNeedAddress(true);//若不加此句,将无法显示省市街道等信息
mLocClient.setLocOption(option);
3.自定义Dialog时主题的设定问题
在写dialog时,自定义了一个layout,但是会弹出的dialog会出现一个莫名其妙的边,经资料查阅发现是style的问题,解决方案如下:
在styles.xml中添加新的style
<style name="StyleDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
//设置背景为透明
<item name="android:windowNoTitle">true</item>
// 设置无标题
<item name="android:backgroundDimEnabled">true</item>
// 此属性可以翻译为 是否允许对话框的背景变暗?如果允许背景就变暗了。
</style>
在java文件中添加如下语句(其中,dialog也可以在manifest中改变主题)
builder = new AlertDialog.Builder(mContext,R.style.StyleDialog);
自己写的dialog是介个样子的
public void dialogShow1(StringBuilder currentPosition,Context mContext){
builder = new AlertDialog.Builder(mContext,R.style.StyleDialog);
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.dialog1,null);
TextView address = (TextView)view.findViewById(R.id.tv_address);
address.setText(currentPosition);
Button dialog_close = (Button) view.findViewById(R.id.close);
final Dialog dialog = builder.create();
dialog.show();
dialog.getWindow().setContentView(view);
dialog_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}