首页 > 解决方案 > 添加更新删除和搜索

问题描述

谁能帮我在android studio中发送添加更新删除的代码我已经完成更新但无法正常工作

 public boolean updateInfor(String username, String dob, String password, String gender){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues con = new ContentValues();
    con.put(UserProfile.Users.DOB, dob);
    con.put(UserProfile.Users.PASSWORD, password);
    con.put(UserProfile.Users.GENDER, gender);

    String where = UserProfile.Users.USERNAME + " = ?";
    String[] wheree = {username};

    long r = db.update(UserProfile.Users.TABLE_NAME, con, where, wheree);

    if(r == 1)
        return false;
    else
        return true;
}

标签: android

解决方案


公共无效编辑按钮(查看视图){

    DBHelper db = new DBHelper(this);

    un = (EditText) findViewById(R.id.editText9);
    dob = (EditText) findViewById(R.id.editText10);
    pw = (EditText) findViewById(R.id.editText11);

    int res = gender.getCheckedRadioButtonId();
    String ress = String.valueOf(res);

    boolean x = db.updateInfor(un.getText().toString(), dob.getText().toString(), pw.getText().toString(), ress);

    if(x == false)
        Toast.makeText(this, "Unsuccessfull", Toast.LENGTH_SHORT);
    else
        Toast.makeText(this, "Successfull", Toast.LENGTH_SHORT);
}

public void delete(View view){
    DBHelper db = new DBHelper(this);

    un = (EditText) findViewById(R.id.editText9);

    db.deleteInfo(un.getText().toString());
}

public void ReadAll(View view){
    DBHelper db = new DBHelper(this);

    Cursor cursor = db.readAllInfor();

    List <String> l1 = new  ArrayList<>() ;

    while(cursor.moveToNext()){
        l1.add(cursor.getString(0));
        l1.add(cursor.getString(1));
        l1.add(cursor.getString(2));
        l1.add(cursor.getString(3));
    }

    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    CharSequence[] ch = l1.toArray(new CharSequence[l1.size()]);

    alert.setItems(ch, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });

    alert.show();
}

public void ReadOne(View view){ DBHelper db = new DBHelper(this);

    un = (EditText) findViewById(R.id.editText9);
    dob = (EditText) findViewById(R.id.editText10);
    pw = (EditText) findViewById(R.id.editText11);
    Cursor cursor = db.readAllInfor(un.getText().toString());

    while(cursor.moveToNext()){
        dob.setText(cursor.getString(1));
        pw.setText(cursor.getString(2));
    }
}

推荐阅读