每日总结

  完成了注册登录功能后,就该进行信息的填写了,这次填写包括姓名,时间,位置,体温,按照需求,只需要用户填写体温即可,其信息都是自动获得,而这些要填写的信息也是比较好获得的,Activity有从一个Activity下一个打开的Activity传递信息的功能,因此对于某些信息只要保持一直传递即可保证信息的完整。

信息填写的代码如下:

public class ADDJL extends AppCompatActivity {   

    private DataBase databaseHelper; 
  private LocationManager locationManager;
private SQLiteDatabase db;
private static final String name = "JZ.db";
private static final int version = 1;
private String id;
private String banji;
private String time1;
private String time2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a_d_d_j_l);
TextView text=(TextView)findViewById(R.id.textView13);
Intent intent = getIntent();
text.setText(intent.getStringExtra("NowTime1")+intent.getStringExtra("NowTime2"));
id=intent.getStringExtra("ThisID");
banji=intent.getStringExtra("banji");
time1=intent.getStringExtra("NowTime1");
time2=intent.getStringExtra("NowTime2");
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
startRequestLocation();
}
public void tijiao(View view){
TextView time=(TextView)findViewById(R.id.textView13);
TextView dizhi=(TextView)findViewById(R.id.textView15);
Intent intent=getIntent();
EditText ed1=(EditText)findViewById(R.id.editTextNumberDecimal);
CheckBox ch1=findViewById(R.id.checkBox);
CheckBox ch2=findViewById(R.id.checkBox2);
CheckBox ch3=findViewById(R.id.checkBox4);
CheckBox ch4=findViewById(R.id.checkBox5);
CheckBox ch5=findViewById(R.id.checkBox6);
StringBuilder str=new StringBuilder();
StringBuilder str1=new StringBuilder();
if(ch1.isChecked()==true){
str.append("无");
str1.append("无");
}

if (ch2.isChecked() == true) {
str.append("2020年12月27日至今去过或现在居住在中高风险地区 ");
str1.append("2020年12月27日至今去过或现在居住在中高风险地区 ");
}
if (ch3.isChecked() == true) {
str.append("本人或家人正在集中隔离 ");
str1.append("本人或家人正在集中隔离");
}
if (ch4.isChecked()) {
str.append("今日居住地异动 ");
str1.append("今日居住地异动");
}
if (ch5.isChecked() == true) {
str.append("其他情况");
str1.append("其他情况");
}

if(ch1.isChecked()&&(ch2.isChecked()||ch3.isChecked()||ch4.isChecked()||ch5.isChecked())){
Toast.makeText(getApplicationContext(), "选择无后不可选择其他", Toast.LENGTH_SHORT).show();
}
else {
EditText yuanyin = (EditText) findViewById(R.id.editTextTextPostalAddress);
databaseHelper = new DataBase(this, name, null, version);
DataBase moh = new DataBase(this, "JZ.db", null, 1);
SQLiteDatabase db = moh.getReadableDatabase(); // 以只读的方式打开数据库
// db.execSQL("insert into jilu(xuehao, riqi,time, dizhi, wendu,teshu,yuanyin,banji) values(?, ?,?, ?, ?,?,?,?)", new Object[]{id, time1,time2, dizhi.getText().toString(), ed1.getText().toString(), str.toString(), yuanyin.getText().toString(),banji});
for(int i=0;i<5;i++){
db.execSQL("insert into jilu(xuehao, riqi,time, dizhi, wendu,teshu,yuanyin,banji) values(?, ?,?, ?, ?,?,?,?)", new Object[]{id, "2020年3月"+(i+5)+"日",time2, dizhi.getText().toString(), "36."+i, str.toString(), yuanyin.getText().toString(),banji});
}
Toast.makeText(getApplicationContext(), "添加成功", Toast.LENGTH_SHORT).show();
finish();
}

}
private void startRequestLocation() {
boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!gps) {
Toast.makeText(this, "请先设置界面开启Gps定位服务", Toast.LENGTH_LONG).show();
return;

}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

return;
}
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
showLocation(location);

}

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, locationListener);


}

private LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
showLocation(location);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}
@Override
public void onProviderEnabled(String s) {

}
@Override
public void onProviderDisabled(String s) {

}
};

private void showLocation(Location location) {
TextView tex=(TextView)findViewById(R.id.textView15);
if (location != null) {
}
Geocoder geocoder= new Geocoder(this, Locale.CHINA);
try{
List<Address> addressList=geocoder.getFromLocation(location.getLatitude(),location.getLongitude(),1);
for (Address address :addressList){
tex.setText(address.getCountryName()+""+address.getLocality()+address.getFeatureName());//+address.getFeatureName()
}
}catch(IOException e){
e.printStackTrace();
}
}

@Override
protected void onDestroy() {
super.onDestroy();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

return;
}
locationManager.removeUpdates(locationListener);

}
这样就完成了信息的登记并且可以保存在数据库中。
原文地址:https://www.cnblogs.com/ruangongwangxiansheng/p/14907975.html