1.今日收获内容
今天解决了昨天问题,并且写完了注册
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/top" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用户注册" android:gravity="center" android:textSize="30sp" /> <TextView android:layout_width="wrap_content" android:layout_height="46dp" android:text="学号:" android:textSize="30dp" /> <EditText android:id="@+id/edit_11" android:layout_width="match_parent" android:layout_height="55dp" android:hint="请填写学号"/> <TextView android:layout_width="wrap_content" android:layout_height="46dp" android:text="姓名:" android:textSize="30dp" /> <EditText android:id="@+id/edit_12" android:layout_width="match_parent" android:layout_height="55dp" android:hint="请填写姓名"/> <TextView android:layout_width="wrap_content" android:layout_height="46dp" android:text="手机号:" android:textSize="30dp" /> <EditText android:id="@+id/edit_13" android:layout_width="match_parent" android:layout_height="55dp" android:hint="请填写手机号"/> <TextView android:layout_width="wrap_content" android:layout_height="46dp" android:text="班级:" android:textSize="30dp" /> <EditText android:id="@+id/edit_14" android:layout_width="match_parent" android:layout_height="55dp" android:hint="请填写班级"/> <Button android:id="@+id/button11" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册" /> </LinearLayout>
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(""); } } }); } }
2.遇到的问题
界面优化问题
3.明天目标
把界面改改