体温登记app开发流程
阅读原文时间:2023年07月16日阅读:1

关于体温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{

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


<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="获取定位" />

activity_index.xml


<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" />

item_recycler_view.xml






        <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="编辑" />

以上是全部源程序代码,具体如何定位,参考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。

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器