package com.example.daka; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import com.example.daka.database.UserDBHelper; import com.example.daka.enity.User; import com.example.daka.util.ToastUtil; public class ZuceActivity extends AppCompatActivity implements View.OnClickListener { private EditText et_name; private EditText et_phone; private EditText et_classroom; private EditText et_password; private EditText et_ID; private UserDBHelper mHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zuce); et_name=findViewById(R.id.et_name); et_phone=findViewById(R.id.et_phone); et_classroom=findViewById(R.id.et_classroom); et_password=findViewById(R.id.et_password); et_ID=findViewById(R.id.et_ID); findViewById(R.id.btn_zuce).setOnClickListener(this); } @Override protected void onStart() { super.onStart(); mHelper =UserDBHelper.getInstance(this); //mHelper.openWriteLink(); //mHelper.openReadLink(); } @Override protected void onStop() { super.onStop(); mHelper.closeLink(); } @Override public void onClick(View v) { String ID=et_ID.getText().toString(); String name=et_name.getText().toString(); String password=et_password.getText().toString(); String phone=et_phone.getText().toString(); String classroom=et_classroom.getText().toString(); User user=null; switch(v.getId()){ case R.id.btn_zuce: user= new User(Integer.parseInt(ID),name,password,phone,classroom); mHelper.insert(user); if(mHelper.insert(user)>0){ ToastUtil.show(this,"注册成功"); } break; } } }
标签:EditText,数据库,private,连接,AndroidStudio,mHelper,import,et,id From: https://www.cnblogs.com/cinan/p/17226765.html