体温填报app2.0开发

AndroidStudio注册功能实现。

protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zc);
        UserService us=new UserService(ZC.this);
        
        findViews();
        register.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v)
            {
                String sid=xid.getText().toString().trim();
                String sname=name.getText().toString().trim();
                String stel=tel.getText().toString().trim();
                String sbj=bj.getText().toString().trim();
                Log.i("TAG",xid+"_"+name+"_"+tel+"_"+bj);
                UserService uService=new UserService(ZC.this);
                User user=new User();
                user.setXid(sid);
                user.setName(sname);
                user.setTel(stel);
                user.setBj(sbj);
                uService.register(user);
                Toast.makeText(ZC.this, "注册成功", Toast.LENGTH_LONG).show();
                Intent intent=new Intent(ZC.this,P.class);
                startActivity(intent);
            }
        });
    }
    private void findViews()
    {
        xid=(EditText) findViewById(R.id.xid);
        name=(EditText) findViewById(R.id.name);
        tel=(EditText) findViewById(R.id.tel);
        bj=(EditText) findViewById(R.id.bj);
        register=(Button) findViewById(R.id.btn);
    }
private int id;
    private String xid;
    private String name;
    private String tel;
    private String bj;
    public User() { super();}
private DatabaseHelper dbHelper;
    public UserService(Context context){dbHelper=new DatabaseHelper(context);}
    
public boolean register(User user)
    {
        SQLiteDatabase sdb=dbHelper.getReadableDatabase();
        String sql="insert into user(xid,name,tel,bj) values(?,?,?,?)";
        Object obj[]={user.getXid(),user.getName(),user.getTel(),user.getBj()};
        sdb.execSQL(sql, obj);
        return true;
    }

 

posted @ 2021-03-04 21:33  谦寻  阅读(59)  评论(0编辑  收藏  举报