Why dose update creates new id in database? - java

I am trying to update the record, whenever I am updating a record new id is generated with the updated values. The update should happen to the same id. What can be the reason?
Create table :
public void createTable(SQLiteDatabase db){
String CREATE_EVENTS_TABLE = "CREATE TABLE " + TABLE_EVENTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_TITLE + " TEXT,"
+ KEY_FROM_DATE + " DATE,"
+ KEY_TO_DATE + " DATE,"
+ KEY_DAY_OF_WEEK + " TEXT,"
+ KEY_LOCATION + " TEXT,"
+ KEY_NOTIFICATION_TIME + " DATE" + ")";
db.execSQL(CREATE_EVENTS_TABLE);
}
update function :
public int updateEvent(EventData event) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TITLE,event.getTitle());
values.put(KEY_FROM_DATE,event.getFromDate());
values.put(KEY_TO_DATE,event.getToDate());
values.put(KEY_DAY_OF_WEEK,event.getDayOfWeek());
values.put(KEY_LOCATION,event.getLocation());
values.put(KEY_NOTIFICATION_TIME,event.getNotificationTime());
// updating row
return db.update(TABLE, values, KEY_ID + " = ?",
new String[] { String.valueOf(event.getId()) });
}
Calling update function :
db = new EventTableHelper(getApplicationContext());
eventData = new EventData();
db.updateEvent(eventData);
Thank you.
EDIT :
My constructor in EventData is this:
public EventData(String title,String fromDate,String toDate,String dayOfWeek,String location,String notificationTime){
this.title = title;
this.fromDate = fromDate;
this.toDate = toDate;
this.dayOfWeek = dayOfWeek;
this.location = location;
this.notificationTime = notificationTime;
}
and I am adding and updating value using eventData object:
db.addEvent(new EventData(eventTitle, startTime, endTime, dayOfWeek, location,notificationTime));
db.updateEvent(eventData);
The id is getting increased, I am not passing any value to id.
EventData class
public class EventData {
public int id;
public String title;
public String fromDate;
public String toDate;
public String location;
public String dayOfWeek;
public String notificationTime;
public EventData(){}
public EventData(String title,String fromDate,String toDate, String location){
this.title = title;
this.fromDate = fromDate;
this.toDate = toDate;
this.location = location;
}
public EventData(int id,String title,String fromDate,String toDate,String dayOfWeek,String location,String notificationTime){
this.title = title;
this.fromDate = fromDate;
this.toDate = toDate;
this.dayOfWeek = dayOfWeek;
this.location = location;
this.notificationTime = notificationTime;
}
/* public EventData(String title,String fromDate,String toDate,String dayOfWeek,String location,String notificationTime){
this.id = id;
this.title = title;
this.fromDate = fromDate;
this.toDate = toDate;
this.dayOfWeek = dayOfWeek;
this.location = location;
this.notificationTime = notificationTime;
}*/
public void setId(int id) {
this.id = id;
}
public void setTitle(String title) {
this.title = title;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
public void setLocation(String location) {
this.location = location;
}
public void setDayOfWeek(String dayofWeek) {
this.dayOfWeek = dayofWeek;
}
public void setNotificationTime(String notificationTime) {
this.notificationTime = notificationTime;
}
public int getId() {
return id;
}
public String getTitle() {
return title;
}
public String getFromDate() {
return fromDate;
}
public String getToDate() {
return toDate;
}
public String getLocation() {
return location;
}
public String getDayOfWeek() {
return dayOfWeek;
}
public String getNotificationTime() {
return notificationTime;
}
}
I am creating events with child view so I want to update the event on which i will click. For that i have used setTag method to pass id of view.
This is my day fragment
dayplanView = (ViewGroup) view.findViewById(R.id.hoursRelativeLayout);
int id = i.getIntExtra("id",0);
mDb = new EventTableHelper(getActivity());
events = mDb.getAllEvents("Mon");
int tag = 0;
for (EventData eventData : events) {
String datefrom = eventData.getFromDate();
if (datefrom != null) {
String[] times = datefrom.substring(11, 16).split(":");
minutesFrom = Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
String dateTo = eventData.getToDate();
String title = eventData.getTitle();
String location = eventData.getLocation();
if (dateTo != null) {
String[] times1 = dateTo.substring(11, 16).split(":");
minutesTo = Integer.parseInt(times1[0]) * 60 + Integer.parseInt(times1[1]);
}
createEvent(inflater, dayplanView, minutesFrom, minutesTo, title, location, tag);
tag++;
}
return view;
}
private void createEvent(LayoutInflater inflater, ViewGroup dayplanView, int fromMinutes, int toMinutes, String title,String location,int tag) {
final View eventView = inflater.inflate(R.layout.event_view, dayplanView, false);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) eventView.getLayoutParams();
RelativeLayout container = (RelativeLayout) eventView.findViewById(R.id.container);
TextView tvTitle = (TextView) eventView.findViewById(R.id.textViewTitle);
if (tvTitle.getParent() != null)
((ViewGroup) tvTitle.getParent()).removeView(tvTitle);
if(location.equals(""))
{
tvTitle.setText("Event : " + title);
}
else
{
tvTitle.setText("Event : " + title + " (At : " + location +")");
}
int distance = (toMinutes - fromMinutes);
layoutParams.topMargin = dpToPixels(fromMinutes + 9);
layoutParams.height = dpToPixels(distance);
eventView.setLayoutParams(layoutParams);
dayplanView.addView(eventView);
container.addView(tvTitle);
eventView.setTag(tag);
eventView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i = new Intent(getActivity(),AddEventActivity.class);
editMode = true;
i.putExtra("EditMode",editMode);
int tag = 0;
tag =(int)v.getTag();
i.putExtra("tag",tag);
startActivityForResult(i,1);
}
});
}

As we discussed in comments. I think you don't need to be so complex as you are being now,
Just simply do like this,
db.update(TABLE, values, KEY_ID = id, null);
where id means the Integer value OR the value of column KEY_ID that you want to update. Like the value of id will be 5 if you want to update the row with id of 5.

Related

My ListView is not showing my data but showing my package name

I'm using ListView to showing the data retrieved from my database, it suppose work before, but it suddenly doesn't and show things. Normally it should showing things like this (Screenshot from other project):
Edited, post my all code:
public class MainActivity extends AppCompatActivity {
private TextView mTextMessage;
String[] dataDetail;
ArrayList<dataDetail> allDetail = new ArrayList<>();
ListView detailList;
final Context context = this;
final int min = 0;
final int max = 10;
final int random = new Random().nextInt((max - min) + 1) + min;
int score = 0;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
return true;
}
return false;
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
detailList = findViewById(R.id.dataView);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
new GetData().execute();
}
private class GetData extends AsyncTask<Void, Void, ArrayList<dataDetail>> {
protected ArrayList<dataDetail> doInBackground(Void... voids) {
HttpURLConnection urlConnection;
InputStream in = null;
try {
URL url = new URL("http://10.0.2.2:8080/projectServer/DataDetailDB?getdata=true");
urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
String response = convertStreamToString(in);
System.out.println("Server response = " + response);
try {
JSONArray jsonArray = new JSONArray(response);
dataDetail = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
final String customerName = jsonArray.getJSONObject(i).get("customerName").toString();
final String carName = jsonArray.getJSONObject(i).get("carName").toString();
final String appointmentDate = jsonArray.getJSONObject(i).get("appointmentDate").toString();
final String email = jsonArray.getJSONObject(i).get("email").toString();
final String issueDescribe = jsonArray.getJSONObject(i).get("issueDescribe").toString();
final String timeForJob = jsonArray.getJSONObject(i).get("timeForJob").toString();
final String costForJob = jsonArray.getJSONObject(i).get("costForJob").toString();
final String reliableOnCar = jsonArray.getJSONObject(i).get("reliableOnCar").toString();
final String distanceJob = jsonArray.getJSONObject(i).get("distance").toString();
final int finalScore = score;
if (random * Float.parseFloat(timeForJob) < 15) {
score += 1;
} if (random * Float.parseFloat(reliableOnCar) > 15) {
score += 1;
} if (random * Float.parseFloat(distanceJob) > 10) {
score -=1;
} if (random * Float.parseFloat(costForJob) > 40) {
score -=1;
} if(random * Float.parseFloat(timeForJob) + random * Float.parseFloat(reliableOnCar) +
random * Float.parseFloat(distanceJob) + random * Float.parseFloat(costForJob) > 500) {
score += 5;
} else {
score += 0;
}
dataDetail tData = new dataDetail(customerName, carName, appointmentDate, email, issueDescribe, timeForJob, costForJob, reliableOnCar, distanceJob, finalScore);
allDetail.add(tData);
System.out.println("customername = " + customerName + ", Score = " + finalScore);
if (score >= 5) {
dataDetail[i] = "Name: " + customerName + "\n" + "Appointment Date: " + appointmentDate + "\n" + "Urgent";
} else if (score >= 3) {
dataDetail[i] = "Name: " + customerName + "\n" + "Appointment Date: " + appointmentDate + "\n" + "Second urgent";
} else {
dataDetail[i] = "Name: " + customerName + "\n" + "Appointment Date: " + appointmentDate + "\n" + "Normal";
}
System.out.print("Debug: " + dataDetail);
Collections.sort(allDetail, new Comparator<advprog.mmu.ac.uk.schedulerapp.dataDetail>() {
#Override
public int compare(dataDetail o1, dataDetail o2) {
return Integer.compare(o1.getFinalScore(), o2.getFinalScore());
}
});
Collections.reverse(allDetail);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(ArrayList<dataDetail> dataDetailArrayList) {
super.onPostExecute(dataDetailArrayList);
ArrayAdapter List = new ArrayAdapter(context, android.R.layout.simple_list_item_1, allDetail);
detailList.setAdapter(List);
}
}
public String convertStreamToString(InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}}
dataDetial Class:
public class dataDetail {
private String customerName;
private String carName;
private String appointmentDate;
private String email;
private String issueDescribe;
private String timeForJob;
private String costForJob;
private String reliableOnCar;
private String distanceJob;
private int finalScore;
public dataDetail(String customerName, String carName, String appointmentDate, String email, String issueDescribe, String timeForJob, String costForJob, String reliableOnCar, String distanceJob, int finalScore) {
this.customerName = customerName;
this.carName = carName;
this.appointmentDate = appointmentDate;
this.email = email;
this.issueDescribe = issueDescribe;
this.timeForJob = timeForJob;
this.costForJob = costForJob;
this.reliableOnCar = reliableOnCar;
this.distanceJob = distanceJob;
this.finalScore = finalScore;
}
public int getFinalScore() {
return finalScore;
}
public void setFinalScore(int finalScore) {
this.finalScore = finalScore;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCarName() {
return carName;
}
public void setCarName(String carName) {
this.carName = carName;
}
public String getAppointmentDate() {
return appointmentDate;
}
public void setAppointmentDate(String appointmentDate) {
this.appointmentDate = appointmentDate;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getIssueDescribe() {
return issueDescribe;
}
public void setIssueDescribe(String issueDescribe) {
this.issueDescribe = issueDescribe;
}
public String getTimeForJob() {
return timeForJob;
}
public void setTimeForJob(String timeForJob) {
this.timeForJob = timeForJob;
}
public String getCostForJob() {
return costForJob;
}
public void setCostForJob(String costForJob) {
this.costForJob = costForJob;
}
public String getReliableOnCar() {
return reliableOnCar;
}
public void setReliableOnCar(String reliableOnCar) {
this.reliableOnCar = reliableOnCar;
}
public String getDistanceJob() {
return distanceJob;
}
public void setDistanceJob(String distanceJob) {
this.distanceJob = distanceJob;
} }
I think this line dataDetail[i] = "Name: " + customerName + "\n" + "Appointment Date: " + appointmentDate + "\n" + "Urgent"; will be showing the data I want to show in the ListView, but it shows the data like this:
And when I trying to print out the dataDetail, in logcat it gives me this:
I/System.out: customername = Josh, Score = 0
Debug: [Ljava.lang.String;#e883626customername = Wolski, Score = 1
I/System.out: Debug: [Ljava.lang.String;#e883626customername = Cardinal, Score = 2
I/System.out: Debug: [Ljava.lang.String;#e883626customername = Pang, Score = 3
Since you are using the default ArrayAdapter you are rendering the toString() of your dataDetail class. You have at least the following choices:
Define a custom toString() in dataDetail to present the information that you need. Something like:
#Override
public String toString() {
return "Name: " + carName;
}
In order to present the car names.
Define and use a custom adapter where you can use a custom view holder to render the desired data. See here for more details if you are using a RecyclerView.
You can also extend the ArrayAdapter too. See this answer for more details.
I would recommend using a RecyclerView with a custom adapter, instead of the ListView, one similar to what is presented here. This way you gain a lot of flexibility and your app will be able to present a lot of elements in an efficient way. See here a good comparison between the two.
dataDetail tData = new dataDetail(customerName, carName, appointmentDate, email, issueDescribe, timeForJob, costForJob, reliableOnCar, distanceJob, finalScore);
allDetail.add(tData.getCustomerName());
arrya adapter use only string type array list so it put tdata as string in allDetails

table has no column named -Sqlite -android-my first app

Yes I have read many many answers here on SO and tried all but nothing works for me. I dont know what is wrong because according to me everything looks good.
Many times I changed DB version,. Even I renamed db and table name but nothing works. I can print the log which shows the correct result but why it is not inserting into the database.
Also When I remove all the Checkbox fields from table then data insertion works.
A humble request..please do not block me from asking question as this question is asked many times by others and I tried all solutions but nothing worked.
Please guide me as I am completely new to Java and Android Studio.
Sometimes The Error is :
table tblCinFormNew has no column named chkbox_other
Sometimes The Error is :
table tblCinFormNew has no column named chkbox_cosmo
Here is my DatabaseHandler class:
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "dbCinExtDb";
private static final String TABLE_CONTACTS = "tblCinFormNew";
private static final String KEY_ID = "id";
private static final String KEY_EMAIL = "email";
private static final String KEY_PH_NO = "phone_number";
private static final String KEY_WORK_PH_NO = "work_phone_number";
private static final String KEY_FNAME = "fname";
private static final String KEY_LNAME = "lname";
private static final String KEY_ADDRESS = "address";
private static final String KEY_CITY = "city";
private static final String KEY_STATE = "state";
private static final String KEY_ZIP = "zip";
private static final String KEY_SALOON = "chkbox_saloon";
private static final String KEY_COSMO = "chkbox_cosmo";
private static final String KEY_STUDENT = "chkbox_student";
private static final String KEY_OTHER = "chkbox_other";
private static final String KEY_ADD_INFO = "chkbox_add_info";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
#Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = " CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_EMAIL + " TEXT,"
+ KEY_PH_NO + " TEXT," + KEY_WORK_PH_NO + " TEXT, " + KEY_FNAME + " TEXT, "
+ KEY_LNAME + " TEXT," + KEY_ADDRESS + " TEXT,"+ KEY_CITY + " TEXT,"
+ KEY_STATE + " TEXT," + KEY_ZIP + " TEXT " + KEY_SALOON + " TEXT " + KEY_COSMO + " TEXT " + KEY_STUDENT
+ " TEXT " + KEY_OTHER + " TEXT " + KEY_ADD_INFO + " TEXT " + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Upgrading database
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
//db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS_NEW);
// Create tables again
onCreate(db);
}
void addContactNew(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_EMAIL, contact.getEmail());
values.put(KEY_PH_NO, contact.getPhone());
values.put(KEY_WORK_PH_NO, contact.getWorkPhone());
values.put(KEY_FNAME, contact.getFirstName()); // Contact Name
values.put(KEY_LNAME, contact.getlastName());
values.put(KEY_ADDRESS, contact.getAddress());
values.put(KEY_CITY, contact.getCity());
values.put(KEY_STATE, contact.getState());
values.put(KEY_ZIP, contact.getZip());
values.put(KEY_SALOON, contact.getSaloon());
values.put(KEY_COSMO, contact.getCosmo());
values.put(KEY_STUDENT, contact.getStudent());
values.put(KEY_OTHER, contact.getOther());
values.put(KEY_ADD_INFO, contact.getAddInfo());
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
}}
Here is my MainActivity.Java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DatabaseHandler db = new DatabaseHandler(this);
final ProgressDialog progress = new ProgressDialog(this);
Button btn= (Button) findViewById(R.id.btnSave);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText email = (EditText) findViewById(R.id.editTextEmail);
EditText phone = (EditText) findViewById(R.id.editTextPhone);
EditText work_phone = (EditText) findViewById(R.id.editTextPhone1);
EditText fname = (EditText) findViewById(R.id.editTextFirstName);
EditText lname = (EditText) findViewById(R.id.editTextLastName);
EditText address = (EditText) findViewById(R.id.editTextAddress);
EditText city = (EditText) findViewById(R.id.editTextCity);
EditText state = (EditText) findViewById(R.id.editTextState);
EditText zip = (EditText) findViewById(R.id.editTextZip);
CheckBox chkSaloon =(CheckBox) findViewById(R.id.checkBoxSalon);
CheckBox chkCosmo =(CheckBox) findViewById(R.id.checkBoxCosmetologist);
CheckBox chkStudent = (CheckBox) findViewById(R.id.checkBoxStudent);
CheckBox chkOther = (CheckBox) findViewById(R.id.checkBoxOther);
CheckBox chkAddInfo = (CheckBox)findViewById(R.id.checkBoxAdditionalInfo);
String _email=email.getText().toString();
String _phone=phone.getText().toString();
String _work_phone=work_phone.getText().toString();
String _fname=fname.getText().toString();
String _lname=lname.getText().toString();
String _address=address.getText().toString();
String _city=city.getText().toString();
String _state=state.getText().toString();
String _zip=zip.getText().toString();
String strSaloon;
String strCosmo;
String strStudent;
String strOther;
String strAdInfo;
if(chkSaloon.isChecked()) {
strSaloon="Salon owner";
}
else{
strSaloon="Not Checked";
}
if(chkCosmo.isChecked()) {
strCosmo="Licensed Cosmetologist";
}
else{
strCosmo="Not Checked";
}
if(chkStudent.isChecked()) {
strStudent="Student";
}
else{
strStudent="Not Checked";
}
if(chkOther.isChecked()) {
strOther="Other";
}
else{
strOther="Not Checked";
}
if(chkAddInfo.isChecked()) {
strAdInfo="Please send me additional information";
}
else{
strAdInfo="Not Checked";
}
Log.d("Insert: ", "Inserting ..");
db.addContactNew(new Contact(_email,_phone,_work_phone,_fname,_lname,_address,_city,_state,_zip,
strSaloon,strCosmo,strStudent,strOther,strAdInfo));
// Reading all contacts
Log.d("Reading Email",_email);
Log.d("Reading Phone",_phone);
Log.d("Reading Work Phone",_work_phone);
Log.d("Reading Fname",_fname);
Log.d("Reading Lname",_lname);
Log.d("Reading Address",_address);
Log.d("Reading City",_city);
Log.d("Reading State",_state);
Log.d("Reading Zip",_zip);
Log.d("Reading Saloon",strSaloon);
Log.d("Reading Cosmo",strCosmo);
Log.d("Reading Student",strStudent);
Log.d("Reading Other",strOther);
Log.d("Reading AddInfo",strAdInfo);
// Log.d("GetContactCount",String.valueOf(db.getContactsCount()));
Log.d("Reading: ", "Reading all contacts..");
List<Contact> contacts = db.getAllContacts();
for (Contact cn : contacts) {
String log = "Id: "+cn.getID() +" ,Name: " + cn.getFirstName() + cn.getFirstName() + " ,Saloon: " + cn.getSaloon()
+ " ,Cosmo: " + cn.getCosmo();
// Writing Contacts to log
Log.d("Name: ", log);
}
}
});
}
}
Here is my Contact.java Constructor
public class Contact {
int id;
String email;
String phone;
String workPhone;
String firstName;
String lastName;
String address;
String city;
String state;
String zip;
String chkSalon;
String chkCosmo;
String chkStudent;
String chkOther;
String chkAddInfo;
public Contact()
{
// Empty Constructor
}
public Contact(int id, String email, String phone, String workPhone,String firstName,
String lastName, String address,String city , String state,String zip, String chkSalon,
String chkCosmo, String chkStudent, String chkOther,String chkAddInfo
){
this.id = id;
this.email = email;
this.phone = phone;
this.workPhone=workPhone;
this.firstName=firstName;
this.lastName=lastName;
this.address=address;
this.city=city;
this.state=state;
this.zip=zip;
this.chkSalon=chkSalon;
this.chkCosmo=chkCosmo;
this.chkStudent=chkStudent;
this.chkOther=chkOther;
this.chkAddInfo=chkAddInfo;
}
// constructor
public Contact(String email, String phone, String workPhone,String firstName,
String lastName, String address,String city , String state,String zip, String chkSalon,
String chkCosmo, String chkStudent, String chkOther,String chkAddInfo
){
this.email = email;
this.phone = phone;
this.workPhone=workPhone;
this.firstName=firstName;
this.lastName=lastName;
this.address=address;
this.city=city;
this.state=state;
this.zip=zip;
this.chkSalon=chkSalon;
this.chkCosmo=chkCosmo;
this.chkStudent=chkStudent;
this.chkOther=chkOther;
this.chkAddInfo=chkAddInfo;
}
// getting ID
public int getID(){
return this.id;
}
// setting id
public void setID(int id){
this.id = id;
}
public String getPhone(){
return this.phone;
}
public void setPhone(String phone){
this.phone = phone;
}
public String getWorkPhone(){
return this.workPhone;
}
public void setWorkPhone(String workPhone){
this.workPhone = workPhone;
}
public String getEmail(){
return this.email ;
}
public void setEmail(String email){
this.email = email;
}
public String getFirstName(){
return this.firstName;
}
public void setFirstName(String firstName){
this.firstName=firstName;
}
public String getlastName(){
return this.lastName;
}
public void setLastName(String lastName){
this.lastName=lastName;
}
public void setAddress(String address){
this.address=address;
}
public String getAddress(){
return this.address;
}
public String getCity(){
return this.city;
}
public void setCity(String city){
this.city=city;
}
public String getState(){
return this.state;
}
public void setState(String state){
this.state=state;
}
public String getZip(){ return this.zip; }
public void setZip(String zip){
this.zip=zip;
}
public void setSaloon(String chkSalon){
this.chkSalon=chkSalon ;
}
public String getSaloon(){ return this.chkSalon; }
public String getCosmo(){ return this.chkCosmo;}
public void setCosmo(String chkCosmo){
this.chkCosmo=chkCosmo ;
}
public String getStudent(){
return this.chkStudent;
}
public void setStudent(String chkStudent){
this.chkStudent=chkStudent ;
}
public String getOther(){
return this.chkOther;
}
public void setOther(String chkOther){
this.chkOther=chkOther ;
}
public String getAddInfo(){
return this.chkAddInfo;
}
public void setAddInfo(String chkAddInfo){
this.chkAddInfo=chkAddInfo ;
}
}
You are missing comma(,) after "TEXT" in your CREATE_CONTACTS_TABLE query
KEY_ZIP + " TEXT " + KEY_SALOON + " TEXT " + KEY_COSMO + " TEXT " + KEY_STUDENT
+ " TEXT " + KEY_OTHER + " TEXT " + KEY_ADD_INFO + " TEXT "
Try after doing this change. It should work, and if you still get this error, check your table structure using Android Device Monitor if you are using emulator and debug your code.

How to pass value to another activity with id of the option clicked from dialog box

I have a ListView which is display several String when i click on a categories it will call and pop out a dialog options menu which has the options of English, Hindi and Cancel. The onClicklistener will be triggered when the user Click one of the category from the Listview such as "Novel", "Book" or "Plays".
What I want to do here is, when the user clicks "Book" and choose language English option, I want to pass category_id and language_id to the next activity.the category_id and language_id are the json object that i got from the server response. So I need to get the category_id selected from listview and pass it to the next activity along with the language_id as seleceted in dialog box.
if this is possible then how? Thanks in advance for your help.
holder.imageView.setImageUrl(Config.TAG_IMAGE_URL+category.getImage(), imageLoader);
holder.textViewName.setText(category.getName());
category_id = category.getId();
language_id = category.getLanguage_id();
holder.imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
handleLanguageDialog();
}
});
}
private AlertDialog handleLanguageDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select Language")
.setItems(R.array.lang, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
switch(which)
{
case 0:// English
break;
case 1://Bengali
break;
}
}
});
return builder.create().show();
}
categ.java
private String id;
private String name;
private String description;
private String image;
private String parent_id;
private String language_id;
private String created;
private String modified;
#Override
public String toString() {
return "Categ{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", description='" + description + '\'' +
", image='" + image + '\'' +
", parent_id='" + parent_id + '\'' +
", language_id='" + language_id + '\'' +
", created='" + created + '\'' +
", modified='" + modified + '\'' +
'}';
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getParent_id() {
return parent_id;
}
public void setParent_id(String parent_id) {
this.parent_id = parent_id;
}
public String getLanguage_id() {
return language_id;
}
public void setLanguage_id(String language_id) {
this.language_id = language_id;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
}
In your first activity pass data like this
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("CATEGORY_ID", category_id);
intent.putExtra("LANGUAGE_ID", language_id);
startActivity(intent);
Now in your next activity recieve data like this
String cat_id = getIntent().getExtras().getString("CATEGORY_ID");
String cat_id = getIntent().getExtras().getString("LANGUAGE_ID");
Pass like this inside your switch case
case 0:
Intent intent = new Intent(YourCurrentActivity.this, Destination.class);
intent.putExtra("category_key", category_id);
intent.putExtra("language_key", language_id);
startActivity(intent);
Intent intent = new Intent(SourceActivity.this,destinationAvtivity.java);
intent.putExtra("category_id",109);
startActivity(theintent);

SQLite db isn't created

I have problem with sqlite database adapter in my project.I'm new to android development so I don't have much idea to how can handle this problem. I want to save user information in data base .Although no error while execution,database doesn't create? can any one help.
DatabaseAdapter :
public class DatabaseAdapter {
private final String TAG = "DatabaseAdapter";
private DatabaseOpenHelper openHelper;
public static final String TBL_PERSONS = "persons";
public static final String PERSON_ID = "_id";
public static final String PERSON_USERNAME = "_username";
public static final String PERSON_HEIGHT = "_height";
public static final String PERSON_WEIGHT = "_weight";
public static final String PERSON_AGE = "_age";
public static final String PERSON_GENDER = "_gender";
public static final String PERSON_PA = "_pa";
public static final String PERSON_BMI = "_bmivalue";
public static final String PERSON_INTERPRETATION = "_bmiInterpretation";
public static final String PERSON_IDEALWEIGHT = "_idealweight";
public static final String PERSON_DAILYCALORIES = "_dailycalories";
// ???????????
public DatabaseAdapter(Context context) {
openHelper = new DatabaseOpenHelper(context, "Persons.db", null, 1);
}
// ====================insert in
// database===========================================================
public Long insertPerson(Person person) {
SQLiteDatabase db = null;
Long id = -1L;
try {
ContentValues values = new ContentValues();
values.put("PERSON_USERNAME", person.getUsername());
values.put("PERSON_HEIGHT", person.getHeight());
values.put("PERSON_WEIGHT", person.getWeight());
values.put("PERSON_AGE", person.getAge());
values.put("PERSON_GENDER", person.getGender());
values.put("PERSON_PA", person.getPa());
values.put("PERSON_BMI", person.getBmivalue());
values.put("PERSON_INTERPRETAION", person.getBmiInterpretation());
values.put("PERSON_IDEALWEIGHT", person.getIdealweight());
values.put("PERSON_DAILYCALORIES", person.getDailycalories());
db = openHelper.getWritableDatabase();
id = db.insert(TBL_PERSONS, null, values);
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
} finally {
if (db != null && db.isOpen())
db.close();
}
return id;
}
// ================delete from
// database=============================================================
public int deletePerson(long id) {
SQLiteDatabase db = null;
int count = -1;
try {
db = openHelper.getWritableDatabase();
count = db.delete(TBL_PERSONS, PERSON_ID + "=?",
new String[] { String.valueOf(id) });
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
} finally {
db.close();
}
return count;
}
// ===============update
// database===================================================================
public int updatePerson(Person person) {
SQLiteDatabase db = null;
int count = -1;
try {
db = openHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(PERSON_USERNAME, person.getUsername());
values.put(PERSON_HEIGHT, person.getHeight());
values.put(PERSON_WEIGHT, person.getWeight());
values.put(PERSON_AGE, person.getAge());
values.put(PERSON_GENDER, person.getGender());
values.put(PERSON_PA, person.getPa());
values.put(PERSON_BMI, person.getBmivalue());
values.put(PERSON_INTERPRETATION, person.getBmiInterpretation());
values.put(PERSON_IDEALWEIGHT, person.getIdealweight());
values.put(PERSON_DAILYCALORIES, person.getDailycalories());
count = db.update(TBL_PERSONS, values, PERSON_ID + "=?",
new String[] { String.valueOf(person.getId()) });
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
} finally {
db.close();
}
return count;
}
// ===================================================================DATABASEOPENHELPER
// CLASS=========================
class DatabaseOpenHelper extends SQLiteOpenHelper {
public DatabaseOpenHelper(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
}
#Override
public void onCreate(SQLiteDatabase db) {
String query = String
.format("create table %s(%$ integer primary key,%s text,%s text,%s text,%s text,%s text,%s tetx,%s text,%s text,%s text,%s text)",
TBL_PERSONS, PERSON_ID, PERSON_USERNAME,
PERSON_HEIGHT, PERSON_WEIGHT, PERSON_AGE,
PERSON_GENDER, PERSON_PA, PERSON_BMI,
PERSON_INTERPRETATION, PERSON_IDEALWEIGHT,
PERSON_DAILYCALORIES);
db.execSQL(query);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
}
person.java (I pass the user data to person.java)
package Databasedata;
public class Person {
private Long id;
private String username;
private float height;
private int weight;
private int age;
private String gender;
private String pa;
private int bmivalue;
private String bmiInterpretation;
private double idealweight;
private double dailycalories;
public double getIdealweight() {
return idealweight;
}
public void setIdealweight(double idealweight) {
this.idealweight = idealweight;
}
public double getDailycalories() {
return dailycalories;
}
public void setDailycalories(double dailycalories) {
this.dailycalories = dailycalories;
}
public int getBmivalue() {
return bmivalue;
}
public void setBmivalue(int bmivalue) {
this.bmivalue = bmivalue;
}
public String getBmiInterpretation() {
return bmiInterpretation;
}
public void setBmiInterpretation(String bmiInterpretation) {
this.bmiInterpretation = bmiInterpretation;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getPa() {
return pa;
}
public void setPa(String pa) {
this.pa = pa;
}
}
MAIN ACTIVITY
public class MainActivity extends Activity {
String gender;
RadioButton maleRadioButton;
RadioButton femaleRadioButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
maleRadioButton = (RadioButton) findViewById(R.id.maleselected);
femaleRadioButton = (RadioButton) findViewById(R.id.femaleselected);
final RadioGroup genderselected = (RadioGroup) findViewById(R.id.selectgender);
genderselected.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup arg0, int selectedId) {
selectedId=genderselected.getCheckedRadioButtonId();
RadioButton genderchoosed = (RadioButton) findViewById(selectedId);
gender= genderchoosed.getText().toString();
}
});
Button saveinformation = (Button) findViewById(R.id.saveinformation);
saveinformation.setOnClickListener(new View.OnClickListener() {
EditText weighttext = (EditText) findViewById(R.id.weighttext);
EditText heighttext = (EditText) findViewById(R.id.heighttext);
EditText usernametext = (EditText) findViewById(R.id.usernametext);
EditText agetext = (EditText) findViewById(R.id.agetext);
Spinner activitytext = (Spinner) findViewById(R.id.chooseactivity);
Button saveinformation = (Button) findViewById(R.id.saveinformation);
String pa = activitytext.getSelectedItem().toString();
#Override
public void onClick(View v) {
if(maleRadioButton.isChecked()) {
gender= maleRadioButton.getText().toString();
} else {
gender = femaleRadioButton.getText().toString();
}
int weight = (int) Float.parseFloat(weighttext.getText()
.toString());
float height = Float.parseFloat(heighttext.getText()
.toString());
String username = usernametext.getText().toString();
int age = (int) Float.parseFloat(agetext.getText().toString());
String pa = activitytext.getSelectedItem().toString();
// BMI
// ============================================================================================
int Bmivalue = calculateBMI(weight, height);
String bmiInterpretation = interpretBMI(Bmivalue);
float idealweight = idealweight(weight, height, gender, pa, age);
double dailycalories=dailycalories(weight,height,gender,pa,age);
// insert in to
// db==================================================================================
Person person = new Person();
person.setUsername(username);
person.setHeight(height);
person.setWeight(weight);
person.setAge(age);
person.setGender(gender);
person.setPa(pa);
person.setBmivalue(Bmivalue);
person.setBmiInterpretation(bmiInterpretation);
person.setIdealweight(idealweight);
person.setDailycalories(dailycalories);
// ?????????????????????????????????????????/
Databasedata.DatabaseAdapter dbAdapter = new Databasedata.DatabaseAdapter(
MainActivity.this);
dbAdapter.insertPerson(person);
Toast.makeText(getApplicationContext(),
Bmivalue + "and you are" + bmiInterpretation,
Toast.LENGTH_LONG).show();
}
});
}
}
One Problem I see is in your insertPerson() method. Don't include the "" in the values.put()
try replacing below code
ContentValues values = new ContentValues();
values.put("PERSON_USERNAME", person.getUsername());
values.put("PERSON_HEIGHT", person.getHeight());
values.put("PERSON_WEIGHT", person.getWeight());
values.put("PERSON_AGE", person.getAge());
values.put("PERSON_GENDER", person.getGender());
values.put("PERSON_PA", person.getPa());
values.put("PERSON_BMI", person.getBmivalue());
values.put("PERSON_INTERPRETAION", person.getBmiInterpretation());
values.put("PERSON_IDEALWEIGHT", person.getIdealweight());
values.put("PERSON_DAILYCALORIES", person.getDailycalories());
with
ContentValues values = new ContentValues();
values.put(PERSON_USERNAME, person.getUsername());
values.put(PERSON_HEIGHT, person.getHeight());
values.put(PERSON_WEIGHT, person.getWeight());
values.put(PERSON_AGE, person.getAge());
values.put(PERSON_GENDER, person.getGender());
values.put(PERSON_PA, person.getPa());
values.put(PERSON_BMI, person.getBmivalue());
values.put(PERSON_INTERPRETATION, person.getBmiInterpretation());
values.put(PERSON_IDEALWEIGHT, person.getIdealweight());
values.put(PERSON_DAILYCALORIES, person.getDailycalories());

Android saving data from edit texts fields to database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am new to SQLite. I have an activity in which I have different fields like Name,Email,Date of Birth etc. When user fill the information and clicks the save button I want it to get saved to the database. But I am stuck in mid way and don't know what to do.How to save the data from Edit Text Views to the database on Save Button click.Please help me.
I am sharing my code.
DataBaseHelper.java
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "NewUserDb.db";
private static final String TABLE_INFO = "info";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_GOAL = "userGOAL";
public static final String COLUMN_NAME = "userName";
public static final String COLUMN_EMAIL = "userEmail";
public static final String COLUMN_DOB = "userDOB";
public static final String COLUMN_HEIGHT = "userHeight";
public static final String COLUMN_WEIGHT = "userWeight";
public static final String COLUMN_GENGER = "userGender";;
public static final String COLUMN_ZIP = "userZIP";
private static final String[] COLUMNS = { COLUMN_ID, COLUMN_GOAL,
COLUMN_NAME, COLUMN_EMAIL, COLUMN_DOB, COLUMN_HEIGHT,
COLUMN_WEIGHT, COLUMN_GENGER, COLUMN_ZIP };
// http://www.techotopia.com/index.php/An_Android_SQLite_Database_Tutorial
/*
* public DatabaseHelper(Context context, String name, CursorFactory
* factory, int version) { super(context, name, factory, version); // TODO
* Auto-generated constructor stub
*
* }
*/
#Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String CREATE_USER_TABLE = "CREATE TABLE User ( "
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "gaol TEXT, "
+ "name TEXT )";
db.execSQL(CREATE_USER_TABLE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS users");
// create fresh books table
this.onCreate(db);
}
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void addUser(NewUserDb newuserdb) {
// for logging
// Log.d("addBook", book.toString());
// 1. get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
// 2. create ContentValues to add key "column"/value
ContentValues values = new ContentValues();
values.put(COLUMN_GOAL, newuserdb.getGoal()); // get title
values.put(COLUMN_NAME, newuserdb.getName()); // get author
values.put(COLUMN_EMAIL, newuserdb.getEmail());
values.put(COLUMN_DOB, newuserdb.getDob());
values.put(COLUMN_HEIGHT, newuserdb.getHeight());
values.put(COLUMN_WEIGHT, newuserdb.getWeight());
values.put(COLUMN_GENGER, newuserdb.getGender());
values.put(COLUMN_ZIP, newuserdb.getZip());
// 3. insert
db.insert(TABLE_INFO, // table
null, // nullColumnHack
values); // key/value -> keys = column names/ values = column
// values
// 4. close
db.close();
}
public NewUserDb getNewUserDb(int id) {
// 1. get reference to readable DB
SQLiteDatabase db = this.getReadableDatabase();
// 2. build query
Cursor cursor = db.query(TABLE_INFO, // a. table
COLUMNS, // b. column names
" id = ?", // c. selections
new String[] { String.valueOf(id) }, // d. selections args
null, // e. group by
null, // f. having
null, // g. order by
null); // h. limit
// 3. if we got results get the first one
if (cursor != null)
cursor.moveToFirst();
// 4. build book object
NewUserDb newUserdb = new NewUserDb();
newUserdb.setId(Integer.parseInt(cursor.getString(0)));
newUserdb.setGoal(cursor.getString(1));
newUserdb.setName(cursor.getString(2));
newUserdb.setEmail(cursor.getString(3));
newUserdb.setDob(cursor.getString(4));
newUserdb.setHeight(cursor.getString(5));
newUserdb.setWeight(cursor.getString(6));
newUserdb.setGender(cursor.getString(7));
newUserdb.setZip(cursor.getString(8));
// Log.d("getBook("+id+")", book.toString());
// 5. return book
return newUserdb;
}
// Deleting single book
public void deleteUser(NewUserDb newuserDB) {
// 1. get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();
// 2. delete
db.delete(TABLE_INFO, COLUMN_ID + " = ?",
new String[] { String.valueOf(newuserDB.getId()) });
// 3. close
db.close();
Log.d("deleteBook", newuserDB.toString());
}
}
NewUserDb.java
public class NewUserDb {
private int id;
private String goal;
private String name;
private String email;
private String dob;
private String height;
private String weight;
private String gender;
private String zip;
public NewUserDb() {
}
public NewUserDb(int id, String goal, String name, String email,
String dob, String height, String weight, String gender, String zip) {
super();
this.id = id;
this.goal = goal;
this.name = name;
this.email = email;
this.dob = dob;
this.height = height;
this.weight = weight;
this.gender = gender;
this.zip = zip;
};
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoal() {
return goal;
}
public void setGoal(String goal) {
this.goal = goal;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String toString() {
return "User [id=" + id + ", goal=" + goal + ", name=" + name
+ ", email=" + email + ", dob=" + dob + ", height=" + height
+ ", weight=" + weight + ", gender=" + gender + ", zip =" + zip
+ "]";
}
}
AccountActivity.java
public class AccountActivity extends Activity {
private EditText et_weight, et_height, et_email, et_dob, et_name;
private Button btn_uploadPhoto, btn_shootPhoto, btn_del, btn_save;
private Switch genderSwitch;
private DatePickerDialog datePickerDialog;
private String year;
private String month;
private String day;
DatabaseHelper dbh = new DatabaseHelper(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.accounts);
btn_shootPhoto = (Button) findViewById(R.id.button1);
btn_uploadPhoto = (Button) findViewById(R.id.button2);
btn_del = (Button) findViewById(R.id.btn_del);
btn_save = (Button) findViewById(R.id.btn_save);
et_dob = (EditText) findViewById(R.id.et_dob);
genderSwitch = (Switch) findViewById(R.id.mySwitch);
et_name = (EditText) findViewById(R.id.et_name);
et_email = (EditText) findViewById(R.id.et_email);
et_height = (EditText) findViewById(R.id.et_height);
et_height.setInputType(InputType.TYPE_CLASS_NUMBER);
et_weight = (EditText) findViewById(R.id.et_weight);
et_weight.setInputType(InputType.TYPE_CLASS_NUMBER);
btn_save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//what to do here ??
}
});
}
try .getText() on your EditText
like yourEditText.getText(); and set it into your NewUserDb and pass the NewUserDb object into addUser method of your DatabaseHelper class
First you declare database create table query string in your DatabaseHelper class like this:
private static final String DATABASE_CREATE_USER = "create table UserInfo("
+ "_id VARCHAR(20)," + "userGOAL VARCHAR(20),"
+ "userName VARCHAR(20)," + "userEmail VARCHAR(20),"
+ "userDOB VARCHAR(20)," + "userHeight VARCHAR(10),"
+ "userWeight VARCHAR(10)," + "userGender VARCHAR(10),"
+ "userZIP VARCHAR(10) "+ ")";
Then write inside onCreate method of DatabaseHelper
db.execSQL(DATABASE_CREATE_USER);
Then declare object of SqliteDatabase and DatabseHelper in your AcountActivity like this:
DatabaseHelper dbHelper;
SQLiteDatabase db;
Afer this write following code inside your button onClick method:
dbHelper= new DatabaseHelper(ActountActivity.this);
db = dbHelper.getWritableDatabase();
ContentValues insertValues = new ContentValues();
insertValues.put("_id", "User_Id");
insertValues.put("userGOAL", "User_Goal");
insertValues.put("userName", "User_Name");
insertValues.put("userEmail", "User_Email");
insertValues.put("userDOB", "User_DOB");
insertValues.put("userHeight", "User_Height");
insertValues.put("userWeight", "User_Weight");
insertValues.put("userGender", "User_Gender");
insertValues.put("userZIP", "User_Zip");
db.insert("UserInfo", null, insertValues);
db.close();
May this help you.

Categories