android - 添加更新删除和搜索
问题描述
谁能帮我在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;
}
解决方案
公共无效编辑按钮(查看视图){
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));
}
}
推荐阅读
- javascript - JSX 不接受三元语句(意外标记“?”)
- r - R从括号内的字符串中提取多个数字正则表达式
- sql - 我可以从 Terraform 脚本填充数据库吗(对于 GCP)
- google-kubernetes-engine - 带有自定义 SSL 证书的 Traefik 2.3 将不起作用
- python - 长度不匹配:预期轴有 0 个元素,新值有 6 个元素
- sql - 如何查找跨 JSON 数组存在重复值的行
- c++ - execvp 做 ps 每次都会给出相同的结果
- lua - 在 Windows 上正确设置 LuaBinaries 文件?
- python - Python 硒网络驱动程序
- r - 尝试使用 R 整理 Excel 工作表