个人冲刺(六)——体温上报app(二阶段)
冲刺任务:完成主页面功能
MainActivity.java
package com.example.helloworld; import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private static final int RESQUEST=100;
private EditText text1;
private EditText text2;
private EditText text3;
private EditText text4;
private TextView text5;
String tempstr="";
private DBOpenHelper mDBOpenHelper;
private WenDate wendate=new WenDate();
private TextView mTv = null;
public LocationClient mLocationClient = null;
private MyLocationListener myListener = new MyLocationListener();
//获取地址
public class MyLocationListener extends BDAbstractLocationListener {
@Override
public void onReceiveLocation(BDLocation location){
//此处的BDLocation为定位结果信息类,通过它的各种get方法可获取定位相关的全部结果
//以下只列举部分获取地址相关的结果信息
//更多结果信息获取说明,请参照类参考中BDLocation类中的说明
String addr = location.getAddrStr(); //获取详细地址信息
String country = location.getCountry(); //获取国家
String province = location.getProvince(); //获取省份
String city = location.getCity(); //获取城市
String district = location.getDistrict(); //获取区县
String street = location.getStreet(); //获取街道信息
String town = location.getTown();
//获取乡镇信息
text4=(EditText)findViewById(R.id.tv_text4);
text4.setText(country+" " +province+" "+city+" "+district+" "+town+" "+street+" ");
}
}
//自动获取地址
public void autoAddress(View view)
{
mLocationClient = new LocationClient(getApplicationContext());
//声明LocationClient类
mLocationClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setIsNeedAddress(true);
option.setNeedNewVersionRgc(true);
mLocationClient.setLocOption(option);
//注册监听函数
mLocationClient.start();
} //
//onCreate方法
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("MainActivity","MainActivity启动");
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
mDBOpenHelper = new DBOpenHelper(this);
text1=findViewById(R.id.tv_text1);
text2=findViewById(R.id.tv_text2);
text3=findViewById(R.id.tv_text3);
text4=findViewById(R.id.tv_text4);
text5=findViewById(R.id.tv_text5);
initView();
EditText et_tiwen=findViewById(R.id.tv_text3);
et_tiwen.setText("体温 36.2℃");
//
//把名字显示到界面
showNmae();
}
//
//接收复选框传过来的数据
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (resultCode)
{
case RESULT_OK:
tempstr=data.getExtras().getString("mess");
Log.v("输出“特殊情况”获取结果 ",data.getExtras().getString("mess"));
text5.setText(tempstr);
break;
default:
break;
}
} private void initView() {
// 初始化控件对象
Button mBtMainLogout = findViewById(R.id.bt_main_logout);
// 绑定点击监听器
mBtMainLogout.setOnClickListener(this);
text5=findViewById(R.id.tv_text5);
text5.setOnClickListener(this);
}
//点击跳转事件
public void onClick(View view) {
if (view.getId() == R.id.bt_main_logout) {
Intent intent = new Intent(this, loginActivity.class);
startActivity(intent);
finish();
}
if (view.getId() == R.id.tv_text5) {
Intent intent = new Intent(this, MoreActivity.class);
intent.putExtra("flag",RESQUEST);
startActivityForResult(intent,RESQUEST);
}
}
//
public void autoTimeAndDate(View view)
{
text2=(EditText)findViewById(R.id.tv_text2);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
//获取当前时间
Date date = new Date(System.currentTimeMillis());
text2.setText(simpleDateFormat.format(date));
}
public void createDB(View view)
{
MyDBHelper mydbh=new MyDBHelper(this,"amydb.db",1);
SQLiteDatabase sqldb=mydbh.getReadableDatabase();
}
public void insertDB(View view)
{
MyDBHelper mydbh=new MyDBHelper(this,"amydb.db",1);
SQLiteDatabase sqldb=mydbh.getReadableDatabase();
ContentValues contentvalues=new ContentValues();
text1=(EditText)findViewById(R.id.tv_text1);
text2=(EditText)findViewById(R.id.tv_text2);
text3=(EditText)findViewById(R.id.tv_text3);
text4=(EditText)findViewById(R.id.tv_text4);
contentvalues.put("name",text1.getText().toString());
contentvalues.put("dateandtime",text2.getText().toString());
contentvalues.put("address",text4.getText().toString());
contentvalues.put("wendu",text3.getText().toString());
contentvalues.put("more",text5.getText().toString());
long flag=sqldb.insert("personwendu",null,contentvalues);
Toast.makeText(this,flag+"条数据加入成功",Toast.LENGTH_LONG).show();
}
// //查看数据
public void queryData(View view)
{
MyDBHelper mydbh=new MyDBHelper(this,"amydb.db",1);
SQLiteDatabase sqldb=mydbh.getReadableDatabase();
Cursor cursor=sqldb.rawQuery("select * from personwendu",null);
String str="";
if(cursor.moveToFirst())
{
do{
String name=cursor.getString(cursor.getColumnIndex("name"));
String dateandtime=cursor.getString(cursor.getColumnIndex("dateandtime"));
String address=cursor.getString(cursor.getColumnIndex("address"));
String wendu=cursor.getString(cursor.getColumnIndex("wendu"));
String more= cursor.getString(cursor.getColumnIndex("more"));
str=str+name+"|"+dateandtime+"|"+wendu+"\n"+address+"\n"+"-----"+more;
}while(cursor.moveToNext());
}
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("历史记录").setIcon(R.mipmap.ic_launcher).setMessage(str)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog ad=builder.create();
ad.show();
}
public void updateData(View view)
{
MyDBHelper mydbh=new MyDBHelper(this,"mydb.db",1);
SQLiteDatabase sqldb=mydbh.getReadableDatabase();
ContentValues contentvalues=new ContentValues();
contentvalues.put("name","hh");
contentvalues.put("age","18");
int flag=sqldb.update("person",contentvalues,"name=?",new String[]{"李明"});
Toast.makeText(this,"已有"+flag+"条数据修改",Toast.LENGTH_LONG).show();
}
public void deleteDate(View view)
{
MyDBHelper mydbh=new MyDBHelper(this,"mydb.db",1);
SQLiteDatabase sqldb=mydbh.getReadableDatabase();
int flag=sqldb.delete("person","id=1",null);
Toast.makeText(this,"已有"+flag+"条数据删除",Toast.LENGTH_LONG).show();
}
//把姓名从数据库里读取出来然后显示到控件上
public void showNmae(){
//先定义一个User类找到数据库最后一条数据里的姓名信息
List list= new ArrayList<User>();
list=mDBOpenHelper.getAllData();
if(list.size()!=0){
TextView et_name=(TextView) findViewById(R.id.tv_text1);
User user = (User) list.get(list.size()-1);
String name1 = user.getUsername();
Log.v("输出查询到的最后一个姓名:",name1);
et_name.setText(name1);
}
else{
Log.v("输出查询到的最后一个姓名:","查询失败!!!");
}
}
}
个人冲刺(六)——体温上报app(二阶段)的更多相关文章
- 个人作业——体温上报app(二阶段)
Code.java package com.example.helloworld; import android.graphics.Bitmap; import android.graphics.Ca ...
- 个人冲刺(二)——体温上报app(二阶段)
冲刺任务:完成app首页.第二页面和特殊情况的页面布局 activity_main.xml <?xml version="1.0" encoding="utf-8& ...
- 个人冲刺(一)——体温上报app(一阶段)
任务:完成了体温上报app的整体页面布局 activity_main.xml <?xml version="1.0" encoding="utf-8"?& ...
- 个人冲刺(一)——体温上报app(二阶段)
冲刺任务:完成app登录和注册页面的布局 activity_register.xml <?xml version="1.0" encoding="utf-8&quo ...
- 个人作业--体温上报APP
第一阶段目标: 1.要求增加用户注册功能,用户注册信息包括用户ID(学号).用户名(姓名),手机号码,用户单位(班级),用户班级四项基本信息,用户第一次注册后,用户姓名不用每次输入 . 2.体温上报界 ...
- 个人冲刺(七)——体温上报app(二阶段)
冲刺任务:完成特殊情况功能 MoreActivity.java package com.example.helloworld; import android.content.Intent; impor ...
- 个人冲刺(五)——体温上报app(二阶段)
冲刺任务:完成用户登录和随机验证码功能 loginActivity.java package com.example.helloworld; /** * 纯粹实现登录注册功能,其它功能都被注释掉了 * ...
- 个人冲刺(四)——体温上报app(二阶段)
冲刺任务:完成用户注册功能和数据库类 RegisterActivity.java package com.example.helloworld; import android.content.Inte ...
- 个人冲刺(三)——体温上报app(二阶段)
冲刺任务:完成用户类.温度数据和第二页面类的编写 User.java package com.example.helloworld; class User { private String usern ...
随机推荐
- 创建axios拦截器
上一篇说axios并发的时候有提到 axios的请求统一管理是为了创建拦截器 具体说一下拦截器的创建 import Vue from 'vue'; import axios from 'axios'; ...
- 推荐一些好用的 HTML5 & JavaScript 游戏引擎开发库
推荐一些好用的 HTML5 & JavaScript 游戏引擎开发库 0. 引言 如果你是一个游戏开发者,并且正在寻找一个可以与 JavaScript 和 HTML5 无缝工作的游戏引擎.那么 ...
- buuoj [RoarCTF 2019]Easy Calc(利用PHP的字符串解析特性)
web [RoarCTF 2019]Easy Calc(利用PHP的字符串解析特性) 先上源码 <?phperror_reporting(0);if(!isset($_GET['num'])){ ...
- 启动两个jboss需要修改的端口号 (两个不能相同)
standalone-configuration-standalone.xml
- 静态变量和成员变量的区别、final修饰特点、创建对象的内存图、静态内存图
静态变量和成员变量的区别* 静态变量也叫类变量 成员变量也叫对象变量* A:所属不同 * 静态变量属于类,所以也称为为类变量 * 成员变量属于对象,所以也称为实例变量(对象变量)* B:内存中位置不 ...
- Ubuntu20.04中创建Pycharm桌面快捷方式
[Desktop Entry] Type=Application Name=Pycharm GenericName=Pycharm3 Comment=Pycharm3:The Python IDE E ...
- Java当中的HashSet
package collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /* * ...
- jquery 日期插件datePicker使用
1.将下载下来的DatePicker压缩包解压后整个放入项目中,不可只引入js和css 2.在html中指定input位置加上class="Wdate"(默认样式不加也可正常显示) ...
- shell、bash和sh区别
shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序.你在提示符下输入的每个命令都由shell先解释然后传给Linux内核. shell 是一个命令语言解释器(co ...
- GopherCon SG 2019 "Understanding Allocations" 学习笔记
本篇是根据 GopherCon SG 2019 "Understanding Allocations" 演讲的学习笔记. Understanding Allocations: th ...