package com.example.s1.pizza;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by s1 on 2015-12-10.
*/
public class DBHelper extends SQLiteOpenHelper {
public DBHelper (Context context) {
super(context, "Pizza.db", null, 1);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE dic ( _id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "dough TEXT, topping TEXT, sidemenu TEXT, pay TEXT);");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS dic;");
onCreate(db);
}
}
DB 생성하는 부분입니다
package com.example.s1.pizza;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.Toast;
public class Order_Main extends Activity implements RadioGroup.OnCheckedChangeListener {
DBHelper helper; //DB 도우미
String dough = "";
String topping = null; //DB에 저장할 변수
RadioGroup dough_Group; //라디오 버튼 그룹
CheckBox topping1;
CheckBox topping2;
CheckBox topping3;
CheckBox topping4;
CheckBox topping5; //체크박스 버튼
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order_main);
helper = new DBHelper(this);
dough_Group = (RadioGroup)findViewById(R.id.dough);
dough_Group.setOnCheckedChangeListener(this);
topping1 = (CheckBox)findViewById(R.id.topping1);
topping2 = (CheckBox)findViewById(R.id.topping2);
topping3 = (CheckBox)findViewById(R.id.topping3);
topping4 = (CheckBox)findViewById(R.id.topping4);
topping5 = (CheckBox)findViewById(R.id.topping5);
}
public void onCheckedChanged (RadioGroup rg, int checked) {
if(dough_Group.getCheckedRadioButtonId() == R.id.dough1) {
dough = "팬";
} else if(dough_Group.getCheckedRadioButtonId() == R.id.dough2) {
dough = "치즈 크러스트";
} else if(dough_Group.getCheckedRadioButtonId() == R.id.dough3) {
dough = "리치 골드";
}
}
public void SideNextBtnClick (View v) {
BoxChecked(); //체크 되있는 체크 버튼을 확인해서 변수에 내용 저장
SQLiteDatabase db;
ContentValues row;
db = helper.getWritableDatabase();
Cursor cursor;
cursor = db.rawQuery("SELECT _id FROM dic ORDER BY _id", null);
int _id = 0; //주문번호
while(cursor.moveToNext()) {
_id = cursor.getInt(0);
}
_id++;
row = new ContentValues();
row.put("_id", _id);
row.put("dough", dough);
row.put("topping", topping);
db.insert("dic", null, row);
cursor.close();
helper.close();
Intent goside_in = new Intent(getApplicationContext(), Order_Side.class);
startActivity(goside_in); //Order_Side로 이동
}
}
DB에 내용 추가하는 부분입니다
처음에 _id를 안넣었을때는 진행이 됬었습니다
근데 리스트뷰로 보여줄때 SimpleCursorAdapter를 사용할려면 _id가 필요하다고 하더라구요
그래서 추가했는데 계속
android.database.sqlite.SQLiteException: no such column: _id (code 1): , while compiling: SELECT _id FROM dic ORDER BY _id 라고 뜹니다
뭐가 잘못된건지 모르겠습니다 ㅠㅠㅠ
도와주세요
아니면 리스트뷰로 보여줄때 SimpleCursorAdapter 대신 쓸수있는거라도 알려주세요