Android Programming Tutorials

(Romina) #1
Getting More Active

}

private View.OnClickListener onSave=new View.OnClickListener() {
public void onClick(View v) {
String type=null;

switch (types.getCheckedRadioButtonId()) {
case R.id.sit_down:
type="sit_down";
break;
case R.id.take_out:
type="take_out";
break;
case R.id.delivery:
type="delivery";
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();
}
};
}

And, here is an implementation of RestaurantHelper with the changes


needed by DetailForm:


package apt.tutorial;

import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;

class RestaurantHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="lunchlist.db";
private static final int SCHEMA_VERSION= 1 ;

public RestaurantHelper(Context context) {

131
Free download pdf