体温登记系统2

今日总结 开始着手写注册功能,将个人信息温度导入到数据库中

package com.example;

import android.app.Activity;

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.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.litepaltest.Person;
import com.example.tiwen.R;

import org.litepal.LitePal;
import org.litepal.LitePalApplication;
import org.litepal.tablemanager.Connector;

public class ZhuCeActivity  extends AppCompatActivity {
    private Button zhuce2;
    private String id;
    private String name;
    private String phone;
    private String danwei;
    private EditText et_danwei;
    private EditText et_id;
    private EditText et_name;
    private EditText et_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zhuce);


        et_danwei=findViewById(R.id.et_danwei);
        et_id=findViewById(R.id.et_id);
        et_name=findViewById(R.id.et_name);
        et_phone=findViewById(R.id.et_phone);
        zhuce2=findViewById(R.id.zhuce);

        zhuce2.setOnClickListener(new View.OnClickListener() {
            @Override
                public void onClick(View v) {

               LitePal.getDatabase();

                id=et_id.getText().toString();
                name=et_name.getText().toString();
                phone=et_phone.getText().toString();
                danwei=et_danwei.getText().toString();
                Person person =new Person();
<?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="match_parent"
    android:orientation="vertical"
>

    <TextView
        android:id="@+id/tv_id"
        android:textSize="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ID:"
        >

    </TextView>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_id"
        android:layout_toRightOf="@id/tv_id"
        ></EditText>
    <TextView
        android:id="@+id/tv_name1"
        android:textSize="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Name:"
        >

    </TextView>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_name"
        android:layout_toRightOf="@id/tv_name1"
        ></EditText>
    <TextView
        android:id="@+id/tv_phone1"
        android:textSize="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Phone:"
        >

    </TextView>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_phone"
        android:layout_toRightOf="@id/tv_phone1"
        ></EditText>
    <TextView
        android:id="@+id/tv_danwei1"
        android:textSize="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="班级:"
        >

    </TextView>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_danwei"
        android:layout_toRightOf="@id/tv_danwei1"
        ></EditText>
    <Button
        android:text="注册"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/zhuce"
        ></Button>
</LinearLayout>


          person.setXuhao(id);
                person.setName(name);
                person.setPhone(phone);
                person.setDanwei(danwei);

                person.save();

                if (person.save()) {
                    Toast.makeText(ZhuCeActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(ZhuCeActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
                }


            }
        });

    }
}

2明天实现定位功能

原文地址:https://www.cnblogs.com/feng747/p/14908475.html