Android Programming Tutorials

(Romina) #1
Asking Permission to Place a Call

and the corresponding update() method, also to accept a phone number:


public void update(String id, String name, String address,
String type, String notes, String phone) {
ContentValues cv=new ContentValues();
String[] args={id};

cv.put("name", name);
cv.put("address", address);
cv.put("type", type);
cv.put("notes", notes);
cv.put("phone", phone);

getWritableDatabase().update("restaurants", cv, "_ID=?",
args);
}

The two query methods, getAll() and getById(), also should return the


phone number from each of their respective queries:


public Cursor getAll(String where, String orderBy) {
StringBuilder buf=new StringBuilder("SELECT _id, name, address, type, notes,
phone FROM restaurants");

if (where!=null) {
buf.append(" WHERE ");
buf.append(where);
}

if (orderBy!=null) {
buf.append(" ORDER BY ");
buf.append(orderBy);
}

return(getReadableDatabase().rawQuery(buf.toString(), null));
}

public Cursor getById(String id) {
String[] args={id};

return(getReadableDatabase()
.rawQuery("SELECT _id, name, address, type, notes, phone FROM
restaurants WHERE _ID=?",
args));
}

341
Free download pdf