我想知道在将数据插入数据库时按下键盘的 DONE 按钮时我应该怎么做?
我在这里使用多个edittext,当谈到最后一个编辑按钮时,我必须将所有数据插入数据库..
private static final String CREATE_DB_TABLE_BUSINESSINFO=
"CREATE TABLE " + TABLE_BUSINESS + "(" +
COL_BID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+
COL_COMPANY_NAME + " TEXT NOT NULL ,"+
COL_ADD1 + " TEXT NOT NULL ," +
COL_ADD2 + " TEXT NOT NULL ," +
COL_ADD3 + " TEXT ,"+
COL_CITY +" TEXT NOT NULL ,"+
COL_PROVINCE + " TEXT NOT NULL ,"+
COL_POSTCODE + " TEXT NOT NULL ," +
COL_TEL1 + " TEXT NOT NULL ,"+
COL_TEL2 + " TEXT ,"+
COL_WEBSITE + " TEXT NOT NULL ,"+
COL_EMAIL + " TEXT NOT NULL ,"+
COL_TWITTER + " TEXT NOT NULL ,"+
COL_FACEBOOK + " TEXT NOT NULL ,"+
COL_WELBO + " TEXT NOT NULL" + ")" ;
private static final String CREATE_BUSINESS_RECORD = "INSERT INTO "
+ TABLE_BUSINESS + " (" + COL_COMPANY_NAME + ", "
+ COL_ADD1+","
+ COL_ADD2+","
+ COL_ADD3+","
+ COL_CITY+","
+ COL_PROVINCE+","
+ COL_POSTCODE+","
+ COL_TEL1+","
+ COL_TEL2+","
+ COL_WEBSITE+","
+ COL_EMAIL+","
+ COL_TWITTER+","
+ COL_FACEBOOK+","
+ COL_WELBO
+ ") VALUES (0,0,0,0,0,0,0,0,0,0,0,0,0,0);";
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_DB_TABLE_BUSINESSINFO);
db.execSQL(CREATE_BUSINESS_RECORD);
}
public void inserRecord(EditText edtxt_company, EditText edtxt_add1,
EditText edtxt_add2, EditText edtxt_add3, EditText edtxt_city,
EditText edtxt_province, EditText edtxt_postcode,
EditText edtxt_tel1, EditText edtxt_tel2, EditText edtxt_website,
EditText edtxt_email, EditText edtxt_twitter,
EditText edtxt_facebook, EditText edtxt_welbo) {
/*SQLiteDatabase mdb1=mDbHelper.getWritableDatabase();*/
ContentValues record = new ContentValues();
record.put("companyname", edtxt_company.toString());
record.put("address1", edtxt_add1.toString());
record.put("address2", edtxt_add2.toString());
record.put("address3", edtxt_add3.toString());
record.put("city", edtxt_city.toString());
record.put("province", edtxt_province.toString());
record.put("postcode", edtxt_postcode.toString());
record.put("tel1", edtxt_tel1.toString());
record.put("tel2", edtxt_tel2.toString());
record.put("website", edtxt_website.toString());
record.put("email", edtxt_email.toString());
record.put("twitter", edtxt_twitter.toString());
record.put("facebook", edtxt_facebook.toString());
record.put("welbo", edtxt_welbo.toString());
mDb.insert(CREATE_DB_TABLE_BUSINESSINFO, null,record); }
IN MAINACTIVITY....FOR ADDING THE DATA.....
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Log.i("Insert Successfully","Insert");
addrow();
}
return false;
}
private void addrow() {
try
{
mDbHelper2.inserRecord(edtxt_company, edtxt_add1,edtxt_add2, edtxt_add3,edtxt_city, edtxt_province,edtxt_postcode,edtxt_tel1,edtxt_tel2,edtxt_website,edtxt_email, edtxt_twitter, edtxt_facebook, edtxt_welbo);
}
catch (Exception e) {
e.printStackTrace();
}