• android 学习


    今天写了注册界面

    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("");
    
                    }
                }
            });
    
    
        }
    }

  • 相关阅读:
    [编程题] 基础 [位运算基础]
    [编程题] lc [191. 位1的个数]
    [编程题] lc [69. x 的平方根]
    php 中php-fpm工作原理
    redis分布式锁
    3种Redis分布式锁的对比
    php使用数据库的并发问题(乐观锁与悲观锁)
    php观察者模式应用场景实例详解
    [Usaco2008 Jan]电话网络
    关于二分图结论的一些证明
  • 原文地址:https://www.cnblogs.com/Nojava/p/14907488.html
Copyright © 2020-2023  润新知