今天写了注册界面
package com.example.myapplication2; import android.content.ContentValues; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; public class zhuce extends AppCompatActivity { private DatabaseHelper2 dbHelper1; private EditText editText11; private EditText editText12; private EditText editText13; private EditText editText14; protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zhuce); dbHelper1=new DatabaseHelper2(this,"TTList2.db",null,3); dbHelper1.getWritableDatabase(); editText11 = (EditText) findViewById(R.id.edit_11); editText12 = (EditText) findViewById(R.id.edit_12); editText13 = (EditText) findViewById(R.id.edit_13); editText14 = (EditText) findViewById(R.id.edit_14); Button button11=(Button)findViewById(R.id.button11); button11.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SQLiteDatabase db=dbHelper1.getWritableDatabase(); ContentValues values=new ContentValues(); String m1=editText11.getText().toString(); String m2=editText12.getText().toString(); String m3=editText13.getText().toString(); String m4=editText14.getText().toString(); values.put("学号",m1); values.put("姓名",m2); values.put("手机号",m3); values.put("班级",m4); if(m1.equals("")||m2.equals("")||m3.equals("")||m4.equals("")) { Toast.makeText(zhuce.this, "信息不全,请补充", Toast.LENGTH_SHORT).show(); } else{ db.insert("TTList2",null,values); //注意别漏掉 values.clear(); Toast.makeText(zhuce.this, "注册成功", Toast.LENGTH_SHORT).show(); editText11.setText("");//保存成功清空学号和姓名信息 editText12.setText(""); editText13.setText(""); editText14.setText(""); } } }); } }