• 2021年1月29日 体温上报app03


    今天写了昨天页面的功能,可以连接数据库,填写数据,显示出来,明天继续。

    体温详情列表:

    package bjfu.it.sun.tem;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ListView;
    
    import bjfu.it.sun.tem.model.db.UserAccountDB;
    import bjfu.it.sun.tem.model.dean.Teminfo;
    
    import static bjfu.it.sun.tem.model.dao.UserAccountTable.TAB_NAME2;
    
    //体温详情列表
    public class CheckActivity extends AppCompatActivity implements View.OnClickListener  {
        private ListView lv;
        private Button bt_can;
        private MyAdapter adapter ;
    
        private UserAccountDB userAccountDB ;
        private SQLiteDatabase dbReader;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_check);
    
            initView();
        }
    
        private void initView(){
            lv=findViewById(R.id.check_tem_lv ) ;
          // bt_can =findViewById(R.id.check_tem_cancel ) ;
           // bt_can.setOnClickListener(this) ;
    
            userAccountDB =new UserAccountDB(this);
            dbReader = userAccountDB .getReadableDatabase() ;
        }
    
        @Override
        public void onClick(View v) {
            switch(v.getId() ){
    
            }
        }
    
        //获取数据
        public void selectDB(){
            Cursor cursor =dbReader .query(TAB_NAME2,null,null,null,null,null,null) ;
            adapter =new MyAdapter(this,cursor );
            lv.setAdapter(adapter) ;
        }
    
        @Override
        protected void onResume() {
    
            super.onResume();
            selectDB();
        }
    }

    添加体温:

    package bjfu.it.sun.tem;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.Toast;
    
    import com.baidu.location.BDLocation;
    import com.baidu.location.BDLocationListener;
    import com.baidu.location.LocationClient;
    import com.baidu.location.LocationClientOption;
    import com.baidu.mapapi.SDKInitializer;
    import com.baidu.mapapi.map.MapView;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import bjfu.it.sun.tem.model.dao.TemperatureAccounrDao;
    import bjfu.it.sun.tem.model.dao.UserAccountDao;
    import bjfu.it.sun.tem.model.dean.Teminfo;
    import bjfu.it.sun.tem.util.SPDDataUtils;
    
    public class AddTemActivity  extends AppCompatActivity implements View.OnClickListener  {
        EditText et_name,et_time,et_temper,et_address;//编辑框,要录入的内容,姓名、时间等等
        Button submit,cancel;//定义的两个按钮
    
        CheckBox cb1,cb2,cb3,cb4,cb5;//复选框
        EditText ecb2,ecb3,ecb4,ecb5;//复选框的说明编辑框
    
        private MapView mMapView = null;
        protected LocationClient client;//定位
        private boolean isFirst = true;
    
    
        private Teminfo teminfo ;
        private UserAccountDao userAccountDao ;
        private TemperatureAccounrDao temperatureAccounrDao ;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            SDKInitializer.initialize(getApplicationContext());
            //    SDKInitializer.initialize(this);
            setContentView(R.layout.activity_add_tem );
    
           mMapView = this.findViewById(R.id.bmapView);
    
    
            //初始化地图定位
            client = new LocationClient(this);
            client.registerLocationListener(new MyListener());//注册位置监听器
            LocationClientOption option = new LocationClientOption();
            option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
            option.setScanSpan(100000);  //多长时间,可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
            option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
            option.setOpenGps(true);//可选,默认false,设置是否使用gps
            client.setLocOption(option);//把他设置进去
    
            initView();
        }
    
        public void initView(){
           // 编辑框,要录入的内容,姓名、时间等等
            et_name=findViewById(R.id.add_tem_name) ;
            et_name.setText(getName()) ;
            et_time=findViewById(R.id.add_tem_time ) ;
            et_time.setText(getTime()) ;
            et_temper=findViewById(R.id.add_tem_tempwe) ;
            et_address=findViewById(R.id.add_tem_address) ;
    
            //submit,cancel;//定义的两个按钮
            submit=findViewById(R.id.add_tem_submit) ;
            cancel=findViewById(R.id.add_tem_cancel) ;
    
            //添加事件监听器
            submit .setOnClickListener(this) ;
            cancel .setOnClickListener(this) ;
    
            //cb1,cb2,cb3,cb4,cb5复选框
            cb1=findViewById(R.id.add_cb_1) ;
            cb2=findViewById(R.id.add_cb_2) ;
            cb3=findViewById(R.id.add_cb_3) ;
            cb4=findViewById(R.id.add_cb_4) ;
            cb5=findViewById(R.id.add_cb_5) ;
    
            //ecb2,ecb3,ecb4,ecb5;//复选框的说明编辑框
            ecb2=findViewById(R.id.add_cb_2_other ) ;
            ecb3=findViewById(R.id.add_cb_3_other ) ;
            ecb4=findViewById(R.id.add_cb_4_other ) ;
            ecb5=findViewById(R.id.add_cb_5_other ) ;
    
        }
    
        @Override
        public void onClick(View v) {
            Intent i;
            switch (v.getId() ){
                case R.id.add_tem_submit :
                    addUser();
                    showMSg("体温填报成功");
                    i=new Intent(this,LoginActivity.class);
                    startActivity(i);
                    finish() ;
                    break;
                case R.id.add_tem_cancel:
                    i=new Intent(this,LoginActivity.class);
                    startActivity(i);
                    finish() ;
            }
        }
    
        //生成其他复选框的内容
        private String creatOther(){
            String other="";
            if(cb2.isChecked()){
                other+=ecb2.getText() .toString() ;
                cb1.setChecked(false) ;
            }
            if(cb3.isChecked()){
                other+=ecb3.getText() .toString() ;
                cb1.setChecked(false) ;
            }
            if(cb4.isChecked()){
                other+=ecb4.getText() .toString() ;
                cb1.setChecked(false) ;
            }
            if(cb5.isChecked()){
                other+=ecb5.getText() .toString() ;
                cb1.setChecked(false) ;
            }
            if(cb1.isChecked()){
                other+=ecb2.getText() .toString() ;
                other="无特殊情况";
            }
    
            return other;
        }
        //得到手机号
        private String getPhone(){
            String str=null;
            str= SPDDataUtils.getUserinfo(this) ;
            return str;
        }
    
        //得到姓名
        private String getName(){
            String str;
            userAccountDao=new UserAccountDao(this) ;
            str=userAccountDao .getAccountByPhone(getPhone()).getName() ;
            return str;
        }
    
        //EditText et_name,et_time,et_temper,et_address;//编辑框,要录入的内容,姓名、时间等等
        //添加到数据库
        private void addUser(){
            String name=et_name.getText() .toString() ;
            String time=et_time.getText() .toString() ;
            String temper=et_temper.getText() .toString() ;
            String address=et_address.getText() .toString() ;
            String others=creatOther() ;
            teminfo =new Teminfo(name,time,temper ,address ,others ) ;
            temperatureAccounrDao  =new TemperatureAccounrDao(this);
            temperatureAccounrDao .addAccount(teminfo) ;
        }
    
        //显示时间
        private String getTime(){
            SimpleDateFormat format =new SimpleDateFormat("yyyy年MM月dd日 HH:mm") ;
            Date date=new Date() ;
            String str=format.format(date) ;
            return str;
        }
    
        //显示信息的方法
        private void showMSg(String msg){
            Toast.makeText(this,msg,Toast.LENGTH_LONG  ).show() ;
        }
    
    
    }
  • 相关阅读:
    MSB4064 错误
    javascript 通过模块模式实现代码访问控制
    vs 2012 更新update4 后出现问题
    html 转 PDF wkhtmltopdf image 不能显示的问题
    Html方式导出word 页头和页脚设置
    使用JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了为 maxJsonLength属性
    经验1-打印web
    DataGridView 多线程更新 数据 解决卡顿问题
    Copy List with Random Pointer [LeetCode]
    Validate Binary Search Tree [LeetCode]
  • 原文地址:https://www.cnblogs.com/j-y-s/p/14903023.html
Copyright © 2020-2023  润新知