查看体温功能可以查看自己所填信息的情况
ShowActivity.java文件:
1 package com.example.application; 2 3 import android.content.Intent; 4 import android.database.Cursor; 5 import android.database.sqlite.SQLiteDatabase; 6 import android.os.Bundle; 7 import android.view.View; 8 import android.widget.Button; 9 import android.widget.TextView; 10 11 import androidx.annotation.Nullable; 12 import androidx.appcompat.app.AppCompatActivity; 13 14 import static com.example.application.Constants.TABLE_NAME; 15 16 public class ShowActivity extends AppCompatActivity implements View.OnClickListener{ 17 private Button btShowzzt; 18 private Button btShowout; 19 private DatabaseHelper myHelper; 20 public SQLiteDatabase db; 21 private String username; 22 String str=""; 23 24 protected void onCreate(@Nullable Bundle savedInstanceState) { 25 Intent intent=getIntent(); 26 username=intent.getStringExtra("user_name"); 27 super.onCreate(savedInstanceState); 28 setContentView(R.layout.activity_show); 29 btShowzzt=(Button)findViewById(R.id.bt_show_zzt); 30 btShowout=(Button)findViewById(R.id.bt_show_out); 31 btShowzzt.setOnClickListener(this); 32 btShowout.setOnClickListener(this); 33 final TextView tv=(TextView)findViewById(R.id.allshow); 34 myHelper=new DatabaseHelper(this); 35 SQLiteDatabase db=myHelper.getWritableDatabase(); 36 Cursor cursor = db.query(TABLE_NAME, null, "name like ?", new String[]{username}, null, null, null);//读取数据库所有信息 37 if(cursor.moveToFirst()){ 38 do{ 39 String name=cursor.getString(cursor.getColumnIndex("name")); 40 String date=cursor.getString(cursor.getColumnIndex("date")); 41 String time=cursor.getString(cursor.getColumnIndex("time")); 42 String location=cursor.getString(cursor.getColumnIndex("location")); 43 String temperature=cursor.getString(cursor.getColumnIndex("temperature")); 44 String situation=cursor.getString(cursor.getColumnIndex("situation")); 45 String tip=cursor.getString(cursor.getColumnIndex("tip")); 46 str+=name+" "+ date+" "+location+" "+temperature+" "+situation+" "+tip+" ";//将数据库信息存到str中并换行 47 }while (cursor.moveToNext()); 48 } 49 cursor.close(); 50 tv.setText(str);//打印信息 51 } 52 53 @Override 54 public void onClick(View v) { 55 switch (v.getId()){ 56 case R.id.bt_show_zzt: 57 Intent intent = new Intent(this, PersonActivity.class); 58 intent.putExtra("user_name",username); 59 startActivity(intent); 60 break; 61 case R.id.bt_show_out: 62 Intent intent2 = new Intent(this, OutActivity.class); 63 intent2.putExtra("user_name",username); 64 startActivity(intent2); 65 break; 66 } 67 } 68 69 }
activity_show.xml文件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:background="@mipmap/bj3" 7 > 8 <LinearLayout 9 android:layout_width="match_parent" 10 android:layout_height="match_parent" 11 android:orientation="vertical" 12 > 13 <TextView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:textSize="20sp" 17 android:text="姓名 时间 位置 体温 情况 备注"/> 18 <TextView 19 android:id="@+id/allshow" 20 android:layout_width="match_parent" 21 android:layout_height="wrap_content" 22 android:layout_marginTop="25dp" 23 android:textSize="15sp" /> 24 <LinearLayout 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 android:layout_marginTop="25dp" 28 android:layout_gravity="center" 29 android:orientation="horizontal"> 30 <Button 31 android:id="@+id/bt_show_zzt" 32 android:layout_width="wrap_content" 33 android:layout_height="wrap_content" 34 android:text="柱状图" 35 android:layout_weight="1" 36 android:textColor="#F2F2F2" 37 android:background="#328359" 38 39 android:layout_marginRight="20dp" 40 /> 41 42 <Button 43 android:id="@+id/bt_show_out" 44 android:layout_width="wrap_content" 45 android:layout_height="wrap_content" 46 android:text="打印" 47 android:layout_weight="1" 48 android:textColor="#F2F2F2" 49 android:background="#328359" 50 android:layout_marginLeft="20dp" 51 /> 52 </LinearLayout> 53 54 </LinearLayout> 55 56 57 </ScrollView>
查看记录界面截图:
打印功能可以导出到EXCEL表中,下一篇博客展示