体温上报软件开发

这里是三个功能,获取地址,自动显示姓名,自动显示时间

//---------------------------------------------------------------------自动读取姓名

TextName=findViewById(R.id.TextName);
showName();
//---------------------------------------------------------------------获取当前地址
button_address = (Button) findViewById(R.id.buttonGetAdd);
button_address.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

if (button_address.getText().equals("获取地址")) {
button_address.setText("stop");
//声明AMapLocationClient类对象
//初始化定位
mLocationClient = new AMapLocationClient(getApplicationContext());

//启动定位
mLocationClient.startLocation();
mLocationListener = new AMapLocationListener() {


@Override
public void onLocationChanged(AMapLocation location) {
if (location != null) {
if (location.getErrorCode() == 0) {
//解析定位结果
String result=getAddress(location);
ed_address = findViewById(R.id.editAddress);
ed_address.setText(result);
}

}
}
};
//设置定位回调监听
mLocationClient.setLocationListener(mLocationListener);

//异步获取定位结果
initLocation();

} else if (button_address.getText().equals("stop")) {
button_address.setText("获取地址");
close();

}
}
});

//-------------------------------------------------------------------------自动显示时间
Calendar calendar = Calendar.getInstance();
//年
int year = calendar.get(Calendar.YEAR);
//月
int month = calendar.get(Calendar.MONTH)+1;
//日
int day = calendar.get(Calendar.DAY_OF_MONTH);
//获取系统时间
//小时
int hour = calendar.get(Calendar.HOUR_OF_DAY);
//分钟
int minute = calendar.get(Calendar.MINUTE);
//秒

tv_time = findViewById(R.id.tv_time);
if(minute<10)
{tv_time.setText(year+"年"+month+"月"+day+"日"+hour+":"+"0"+minute);}
else {tv_time.setText(year+"年"+month+"月"+day+"日"+hour+":"+minute);}



}
原文地址:https://www.cnblogs.com/D10304/p/14910391.html