My name is Michael, and I am writing an android application that will serve as a very basic class schedule app. So far, I have been able to write the program so that I am able to create and add new classes to the database, however I cannot seem to figure out how to remove a selected entry from the database. The button that saves the entries is defined as follows:
<Button
android:id="@+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Save" />
and the listener that it activates is:
private View.OnClickListener onSave=new View.OnClickListener() {
public void onClick(View v) {
String type=null;
switch (types.getCheckedRadioButtonId()) {
case R.id.math:
type="math";
break;
case R.id.cs:
type="cs";
break;
case R.id.pe:
type="pe";
break;
case R.id.elective:
type="elective";
break;
}
if (restaurantId==null) {
helper.insert(name.getText().toString(),
address.getText().toString(), type,
notes.getText().toString());
}
else {
helper.update(restaurantId, name.getText().toString(),
address.getText().toString(), type,
notes.getText().toString());
}
finish();
}
};
Where the ‘insert()’ method is the function in my helper class that adds the entry.
The specific problem is that I am having trouble writing the ‘remove()’ function in the helper class. I have tried using the getWritableDatabase.delete() function, however I am having trouble finding the right parameters. Any point in the right direction would be a big help to me. Thank you in advance.
If it helps at all, this is the insert() function:
public void insert(String name, String address,
String type, String notes) {
ContentValues cv=new ContentValues();
cv.put("name", name);
cv.put("address", address);
cv.put("type", type);
cv.put("notes", notes);
getWritableDatabase().insert("restaurants", "name", cv);
}
Are you interested in something like this?
Here the parameter value for the deleteValue() is the one on which basis we are willing to delete a row (like delete rows based on the name) so we are using it as where clause.
see the lines
This can be assumed as delete statement with where clause as
where name = value;