体温登记app开发流程

关于体温app,比较难的是获取定位信息,剩下的就是增删改查。

设计思路:首先布局一个添加页面,给每个元件添加id,之后在获取地点的EditText获取位置信息,在添加两个布局文件,体现在一个页面里用来记录每天的体温,并且可以修改每日的信息。

源程序代码(底下有链接):

MainActivity.java(之前的小程序在判断添加的数据和修改数据的时候有点bug,现已修改

用于添加数据

 

复制代码
package com.example.temperature;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.example.temperature.adapter.Temp;
import com.example.temperature.dao.UserDao;
import com.example.temperature.model.User;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity {
    private Button btn_submit;
    private Button btn_adr;
    private Button btn_back;
    private EditText et_name;
    private TextView tv_time;
    private EditText et_temperature;
    private EditText et_place;
    private RadioGroup rg_gender;
    private  RadioButton radioButton;
    private LocationService locationService;
    private MysqliteOpenHelper dbHelper;
    private MysqliteOpenHelper dbHelper1;
    private User edititem=null;
    private UserDao userDao;
    private RadioButton rb_boy;
    private RadioButton rb_girl;
    private String waterIn;
    Date date=new Date();
    SimpleDateFormat simpleDateFormat  =new SimpleDateFormat("yyyy-MM-dd");
    String time = simpleDateFormat.format(date);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initUI();
        initData();

        locationService = new LocationService(this);
        locationService.registerListener(mListener);
        locationService.setLocationOption(locationService.getDefaultLocationClientOption());
    }
    public void initUI(){
        btn_submit=findViewById(R.id.btn_submit);
        et_name=findViewById(R.id.et_name);
        tv_time=findViewById(R.id.tv_time);
        et_temperature=findViewById(R.id.et_temperature);
        et_place=findViewById(R.id.et_place);
        rg_gender=findViewById(R.id.rg_gender);
        btn_adr=findViewById(R.id.btn_adr);
        btn_back=findViewById(R.id.btn_back);
        rg_gender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                   radioButton = (RadioButton)findViewById(rg_gender.getCheckedRadioButtonId());
                     waterIn = radioButton.getText().toString();
                    Log.i("radio", waterIn);
                }
            });
        btn_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // radioButton = (RadioButton)findViewById(rg_gender.getCheckedRadioButtonId());
                UserDao userDao=new UserDao(MainActivity.this);
                String name=et_name.getText().toString();
                String gender=waterIn;
                String temperature=et_temperature.getText().toString();
                String place=et_place.getText().toString();
                if(name.trim().length()==0){
                    Toast.makeText(MainActivity.this,"姓名不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                if(rg_gender.getCheckedRadioButtonId()==(-1)){
                    Toast.makeText(MainActivity.this,"性别不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                System.out.println(rg_gender.getCheckedRadioButtonId());
                if(temperature.trim().length()==0){
                    Toast.makeText(MainActivity.this,"体温不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                if(place.trim().length()==0){
                    Toast.makeText(MainActivity.this,"地点不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                if(edititem==null){
                    User u=new User(0,time,name,gender,temperature,place);
                    boolean f=userDao.insert(u);
                    if(f){
                        Toast.makeText(MainActivity.this,"提交成功",Toast.LENGTH_SHORT).show();
                    }
                    else{
                        Toast.makeText(MainActivity.this,"提交失败",Toast.LENGTH_SHORT).show();
                    }
                }
                else{
                   //String time_true=userDao.queryTime();
                    edititem.setTime(edititem.getTime());
                    edititem.setName(name);
                    edititem.setTemperature(temperature);
                    edititem.setPlace(place);
                    edititem.setGender(gender);
                    userDao.updateContacter(edititem);
                }
               // locationService.stop();
                finish();
            }
        });
        btn_adr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                locationService.start();
            }
        });
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    public void initData(){
        rb_boy=findViewById(R.id.rb_boy);
        rb_girl=findViewById(R.id.rb_girl);
        userDao=new UserDao(MainActivity.this);
        edititem=(User)getIntent().getSerializableExtra("edititem");
        if(edititem==null){
            tv_time.setText(time);
        }
        if(edititem!=null){
            et_name.setText(edititem.getName());
            et_temperature.setText(edititem.getTemperature());
           et_place.setText(edititem.getPlace());
            if(rb_boy.getText().toString().equals(edititem.getGender()))    ((RadioButton) rg_gender.findViewById(R.id.rb_boy)).setChecked(true);
            if((rb_girl.getText().toString()).equals(edititem.getGender()))    ((RadioButton) rg_gender.findViewById(R.id.rb_girl)).setChecked(true);
           tv_time.setText(edititem.getTime());
           System.out.println(edititem.getTime()+"77");
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        locationService.unregisterListener(mListener); //注销掉监听
        locationService.stop(); //停止定位服务
    }

    /*****
     *
     * 定位结果回调,重写onReceiveLocation方法,可以直接拷贝如下代码到自己工程中修改
     *
     */
    private BDAbstractLocationListener mListener = new BDAbstractLocationListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // TODO Auto-generated method stub
            if (null != location && location.getLocType() != BDLocation.TypeServerError) {
                //button.setText("停止定位");
                StringBuilder sb = new StringBuilder(256);
                /**
                 * 时间也可以使用systemClock.elapsedRealtime()方法 获取的是自从开机以来,每次回调的时间;
                 * location.getTime() 是指服务端出本次结果的时间,如果位置不发生变化,则时间不变
                 */

                sb.append(location.getAddrStr());
                if (location.getLocType() == BDLocation.TypeGpsLocation) {
                } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {// 网络定位结果
                    // 运营商信息
                    if (location.hasAltitude()) {// *****如果有海拔高度*****
                        sb.append("\nheight : ");
                        sb.append(location.getAltitude());// 单位:米
                    }
                } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果
                    sb.append("\ndescribe : ");
                    sb.append("离线定位成功,离线定位结果也是有效的");
                } else if (location.getLocType() == BDLocation.TypeServerError) {
                    sb.append("\ndescribe : ");
                    sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
                } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
                    sb.append("\ndescribe : ");
                    sb.append("网络不同导致定位失败,请检查网络是否通畅");
                } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
                    sb.append("\ndescribe : ");
                    sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
                }
                logMsg(sb.toString());
            }
        }

    };

    /**
     * 显示请求字符串
     */
    public void logMsg(final String str) {
        try {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    et_place.post(new Runnable() {
                        @Override
                        public void run() {
                            et_place.setText(str);
                        }
                    });
                }
            }).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
复制代码

 

 

 

IndexActivity.java(添加RecyclerView的设置)

复制代码
package com.example.temperature;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.temperature.adapter.Temp;
import com.example.temperature.dao.UserDao;
import com.example.temperature.model.User;

import java.util.List;

public class IndexActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btn_back;
    private Button btn_add;
    private Button tv_time;
    private LocationService locationService;
    private RecyclerView rec;
    private UserDao userDao;
    private Temp adapter;
    private final Activity mContext=IndexActivity.this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        initUI();
        initData();
    }
    @Override
    protected void onResume() {
        super.onResume();
        adapter.setList(userDao.queryAll());
        adapter.notifyDataSetChanged();
    }
    public void initUI(){
        btn_back=findViewById(R.id.btn_back);
        btn_add=findViewById(R.id.btn_add);
        btn_back.setOnClickListener(this);
        btn_add.setOnClickListener(this);

        rec=findViewById(R.id.rec);
        rec.setLayoutManager(new LinearLayoutManager(mContext));
        DividerItemDecoration divider = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this,R.drawable.recycler_item));
        rec.addItemDecoration(divider);
    }
    private void initData(){
        userDao =new UserDao(mContext);
        List<User> list=userDao.queryAll();
        adapter=new Temp(mContext,list);
        rec.setAdapter(adapter);
    }
    @Override
    public void onClick(View v) {
        int id=v.getId();
        Intent intent=new Intent();
        switch (id){
            case R.id.btn_back:finish();break;
            case R.id.btn_add:
            intent.setClass(IndexActivity.this,MainActivity.class);
            startActivity(intent);
                break;
        }
    }
}
复制代码

 

LocationService.java(用于定位的服务)

复制代码
package com.example.temperature;

import android.content.Context;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;

public class LocationService {
    private LocationClient client = null;
    private LocationClientOption mOption,DIYoption;
    private Object objLock = new Object();

    public LocationService(Context locationContext){
        synchronized (objLock) {
            if(client == null){
                client = new LocationClient(locationContext);
                client.setLocOption(getDefaultLocationClientOption());
            }
        }
    }

    // 注册
    public boolean registerListener(BDAbstractLocationListener listener){
        boolean isSuccess = false;
        if(listener != null){
            client.registerLocationListener(listener);
            isSuccess = true;
        }
        return  isSuccess;
    }

    // 注销
    public void unregisterListener(BDAbstractLocationListener listener){
        if(listener != null){
            client.unRegisterLocationListener(listener);
        }
    }

    //设置配置
    public boolean setLocationOption(LocationClientOption option){
        boolean isSuccess = false;
        if(option != null){
            if(client.isStarted())
                client.stop();
            DIYoption = option;
            client.setLocOption(option);
        }
        return isSuccess;
    }

    //默认Option设置
    public LocationClientOption getDefaultLocationClientOption(){
        if(mOption == null){
            mOption = new LocationClientOption();
            mOption.setLocationMode(LocationMode.Hight_Accuracy);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
            mOption.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
            mOption.setScanSpan(3000);//可选,默认0,即仅定位一次,设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
            mOption.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
            mOption.setIsNeedLocationDescribe(true);//可选,设置是否需要地址描述
            mOption.setNeedDeviceDirect(false);//可选,设置是否需要设备方向结果
            mOption.setLocationNotify(false);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
            mOption.setIgnoreKillProcess(true);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
            mOption.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
            mOption.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
            mOption.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
            mOption.setOpenGps(true);//可选,默认false,设置是否开启Gps定位
            mOption.setIsNeedAltitude(false);//可选,默认false,设置定位时是否需要海拔信息,默认不需要,除基础定位版本都可用
        }
        return mOption;
    }


    //自定义Option设置
    public LocationClientOption getOption(){
        if(DIYoption == null) {
            DIYoption = new LocationClientOption();
        }
        return DIYoption;
    }

    public void start(){
        synchronized (objLock) {
            if(client != null && !client.isStarted()){
                client.start();
            }
        }
    }
    public void stop(){
        synchronized (objLock) {
            if(client != null && client.isStarted()){
                client.stop();
            }
        }
    }

    public boolean isStart() {
        return client.isStarted();
    }

    public boolean requestHotSpotState(){
        return client.requestHotSpotState();
    }
}
复制代码

model.User.java(封装)

复制代码
package com.example.temperature.model;

import java.io.Serializable;

public class User implements Serializable {
    private Integer id;
    private String time;
    private String name;
    private String gender;
    private String temperature;
    private String place;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getTemperature() {
        return temperature;
    }

    public void setTemperature(String temperature) {
        this.temperature = temperature;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public User(Integer id, String time, String name, String gender, String temperature, String place) {
        this.id = id;
        this.time = time;
        this.name = name;
        this.gender = gender;
        this.temperature = temperature;
        this.place = place;
    }

    public User() {
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", time='" + time + '\'' +
                ", name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", temperature='" + temperature + '\'' +
                ", place='" + place + '\'' +
                '}';
    }
}
复制代码

dao.UserDao.java(方法,连接数据库)

复制代码
package com.example.temperature.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import androidx.annotation.Nullable;

import com.example.temperature.MysqliteOpenHelper;
import com.example.temperature.model.User;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class UserDao {
    private MysqliteOpenHelper helper;
    public UserDao(Context context){
        helper=new MysqliteOpenHelper(context);
    }

    public  boolean updateContacter(User u) {
        SQLiteDatabase db=helper.getReadableDatabase();
        // String sql="select *from user where account='"+account+"' and password='"+password+'"';
        ContentValues values=new ContentValues();
        values.put("name",u.getName());
        values.put("temperature",u.getTemperature());
        values.put("time",u.getTime());
        values.put("place",u.getPlace());
        values.put("gender",u.getGender());

        long update= db.update("user",values,"id=?",new String[]{u.getId()+""});
        System.out.println(u.getId()+"年号");
        return update>0;
    }

    public boolean insert(User u){
        SQLiteDatabase db=helper.getReadableDatabase();
        Date date=new Date();
        SimpleDateFormat simpleDateFormat  =new SimpleDateFormat("yyyy-MM-dd");
        String time = simpleDateFormat.format(date);
        ContentValues values=new ContentValues();
        values.put("time",u.getTime());
        values.put("name",u.getName());
        values.put("gender",u.getGender());
        values.put("temperature",u.getTemperature());
        values.put("place",u.getPlace());
        long insert= db.insert("user",null,values);
        System.out.println(u.getPlace());
        return insert>0;
    }
    public List<User> queryAll(){
        List<User> list=new ArrayList<>();
        User bean=null;
        SQLiteDatabase db=helper.getReadableDatabase();
        Cursor c=db.query("user",null,null,null,null,null,null);
        if(c!=null&&c.getCount()>0){
            list=new ArrayList<>();
            while(c.moveToNext()){
                bean=new User();
                bean.setName(c.getString(c.getColumnIndex("name")));
                bean.setTime(c.getString(c.getColumnIndex("time")));
                bean.setGender(c.getString(c.getColumnIndex("gender")));
                bean.setPlace(c.getString(c.getColumnIndex("place")));
                bean.setTemperature(c.getString(c.getColumnIndex("temperature")));
                bean.setId(c.getInt(c.getColumnIndex("id")));
                list.add(bean);
            }
        }
        return list;
    }
}
复制代码

 

MysqliteOpenHelper.java(创建数据库,创建表)

复制代码
package com.example.temperature;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MysqliteOpenHelper extends SQLiteOpenHelper {

    public MysqliteOpenHelper(@Nullable Context context) {
        super(context, "temp.db", null, 1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table user(id INTEGER PRIMARY KEY AUTOINCREMENT,time VARCHAR(40),name VARCHAR(20),gender VARCHAR(20),temperature VARCHAR(20),place VARCHAR(220))");
       // db.execSQL("create table contacter(id INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR(20),phone VARCHAR(20),pic INTEGER(20))");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
复制代码

adapter.Temp.java(RecyclerView的adapter适配器的使用)

 

复制代码
package com.example.temperature.adapter;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.example.temperature.MainActivity;
import com.example.temperature.R;
import com.example.temperature.model.User;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class Temp extends RecyclerView.Adapter<Temp.TempViewHolder>{

    private Context mContext;
    private List<User> list;
    public Temp (Context context, List<User> list){
        this.mContext=context;
        this.list=list;
    }
    public void setList(List<User> list) {
        this.list=list;
    }
    @NonNull
    @Override
    public TempViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TempViewHolder holder=new TempViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_recycler_view,parent,false));
        return holder;

    }

    @Override
    public void onBindViewHolder(@NonNull TempViewHolder holder, int position) {
        User item=list.get(position);
        holder.tv_name.setText("姓名:"+item.getName());
        holder.tv_time.setText(item.getTime());
        holder.tv_temp.setText("体温:"+item.getTemperature());
        holder.btn_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(mContext, MainActivity.class);
                intent.putExtra("edititem",item);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }


    //绑定单元格空间
    class TempViewHolder extends RecyclerView.ViewHolder{
        TextView tv_name;
        TextView tv_time;
        TextView tv_temp;
        EditText et_name;
        EditText et_gender;
        EditText et_place;
        EditText et_temperature;
        Button btn_edit;


        public TempViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_name=itemView.findViewById(R.id.tv_name);
            tv_time=itemView.findViewById(R.id.tv_time);
            tv_temp=itemView.findViewById(R.id.tv_temp);
           btn_edit=itemView.findViewById(R.id.btn_edit);

        }
    }

}
复制代码

 

activity_main.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@mipmap/ic_great">

    <LinearLayout
        android:id="@+id/canzhao1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/canzhao2"
        android:layout_marginBottom="48dp"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="日期:"
            android:textColor="@color/cardview_dark_background"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:text="666"
            android:textColor="@color/cardview_dark_background"
          />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/canzhao2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout3"
        android:layout_marginBottom="48dp"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓名:"
            android:textColor="@color/cardview_dark_background"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_name"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:hint="请输入姓名"
            android:textColorHint="@color/cardview_dark_background" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_above="@+id/linearLayout4"
        android:layout_marginBottom="48dp"
        android:gravity="center">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="性别:"
            android:textColor="@color/cardview_dark_background"
            android:textSize="20sp" />

        <RadioGroup
            android:id="@+id/rg_gender"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/rb_boy"
                android:layout_width="88dp"
                android:layout_height="wrap_content"
                android:text="男" />

            <RadioButton
                android:id="@+id/rb_girl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="女" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout5"
        android:layout_marginBottom="48dp"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="体温:"
            android:textColor="@color/cardview_dark_background"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_temperature"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:hint="请输入体温(例如:36.5)"
            android:textColorHint="@color/cardview_dark_background"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/canzhao6"
        android:layout_marginBottom="48dp"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="地点:"
            android:textColor="@color/cardview_dark_background"
            android:textSize="20sp" />

        <EditText
            android:id="@+id/et_place"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:hint="请输入地点"
            android:textColorHint="@color/cardview_dark_background"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/canzhao6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="80dp"
        android:gravity="center">

        <Button
            android:id="@+id/btn_submit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="提交" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/canzhao7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/canzhao1"
        android:layout_marginBottom="50dp"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="每日体温填报表"
            android:textColor="@color/cardview_dark_background"
            android:textSize="20sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="(请以实际情况填写)"
            android:textSize="15sp" />
    </LinearLayout>
    <Button
        android:id="@+id/btn_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回" />

    <Button
        android:id="@+id/btn_adr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="获取定位" />


</RelativeLayout>
复制代码

activity_index.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".IndexActivity"
    android:background="@mipmap/ic_great">

    <Button
        android:id="@+id/btn_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:layout_marginEnd="3dp"
        android:layout_marginRight="3dp"
        android:text="填写"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="56dp" />

    <Button
        android:id="@+id/btn_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="3dp"
        android:layout_marginLeft="3dp"
        android:layout_marginTop="1dp"
        android:text="返回"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="85dp"
        android:layout_marginLeft="85dp"
        android:layout_marginTop="14dp"
        android:layout_marginEnd="85dp"
        android:layout_marginRight="85dp"
        android:text="体温填写情况"
        app:layout_constraintEnd_toStartOf="@+id/btn_add"
        app:layout_constraintStart_toEndOf="@+id/btn_back"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rec"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="60dp"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="17dp" />

</androidx.constraintlayout.widget.ConstraintLayout>
复制代码

item_recycler_view.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"
        android:orientation="vertical"
     >
        <TextView
            android:id="@+id/tv_time"
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:text="时间"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <TextView
            android:id="@+id/tv_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_weight="1"
            android:text="姓名:" />

            <TextView
                android:id="@+id/tv_temp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="体温" />


        </LinearLayout>

    </LinearLayout>
    <Button
        android:id="@+id/btn_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="编辑" />

</LinearLayout>
复制代码

以上是全部源程序代码,具体如何定位,参考https://www.cnblogs.com/yuxuan-light-of-Taihu-Lake/p/14354416.html

那么呈现的画面就是:https://www.cnblogs.com/yuxuan-light-of-Taihu-Lake/p/14359500.html

整个项目project:

链接:https://pan.baidu.com/s/1PkH6Q5G4_3r0eVm8aG8F7Q
提取码:i8k7 

 

遇到的问题:

1.定位的时候包名写错了

2.定位的时候手机没有开位置权限,导致一直没有定位成功

3.连接完数据库并存入数据库后,发现找不到数据库了

4.toast一直没有显示,结果发现忘记加.show()

5.radiogroup和radiobutton获取不到数据,现已解决

6.使用约束布局,在虚拟机上可以实现一些布局,发现到真机上排版乱了,原来是没有嵌入合成一个布局,导致不同屏幕的手机会呈现不同的布局

7.toast在手机上没有显示,原来是没有开权限

8.往数据库里面传时间的时候,传成当下的时间里了,导致出现了编辑的时候的bug

 

开发总结:

这个app算是在寒假自学开发的第一个app,懵懵懂懂,遇到了不少问题,也希望接下来能开发出更好的app。

 

posted @   睡觉不困  阅读(350)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示