我正在開發一個android應用程序,我想在textview中顯示主鍵,這樣每次我編輯一個文本字段時,我都會使用主鍵update.can任何人幫助我呢?下面是在sqlite中插入數據。我的問題是如何讓主鍵...插入數據庫後顯示主鍵
public class UsedataActivity extends Activity {
DatabaseHandler db = new DatabaseHandler(this);
ImageButton evsave;
EditText evname;
EditText evtime;
EditText evdate;
EditText evcode;
TextView evadmin;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_onetoone);
evsave = (ImageButton)findViewById(R.id.event_save);
evname = (EditText)findViewById(R.id.eventname);
evtime = (EditText)findViewById(R.id.time1);
evdate = (EditText)findViewById(R.id.eventdate);
evcode = (EditText)findViewById(R.id.eventcode);
evadmin = (TextView)findViewById(R.id.adminname_1to1);
evsave.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Events addev =
new Events(evname.getText().toString(),evcode.getText().toString(),evdate.getText().toString(),Integer.parseInt(evtime.getText().toString()),evadmin.getText().toString());
db.addEvents(addev);
Toast.makeText(getApplicationContext(), "Event: "+ evname.getText()+" successfully save",
Toast.LENGTH_SHORT).show();
}
});
}
數據庫處理類:
public void addEvents(Events event) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_EV_NAME, event.get_name());
values.put(KEY_EV_PASS, event.get_pass());
values.put(KEY_EV_DATE, event.get_date());
values.put(KEY_EV_TIME, event.get_time());
values.put(KEY_EV_ADMIN, event.get_admin());
// Inserting Row
db.insert(TABLE_EVENTS, null, values);
db.close();
}
什麼是'DatabaseHandler'什麼'addEvents'方法呢? –
數據庫處理器的是,我用它來創建表和列的addEvent類是在一個類中的方法,將獲得的值由用戶 –
數據庫處理類 公共無效ADDEVENTS(活動事件){ \t \t SQLiteDatabase DB = inputed this.getWritableDatabase(); \t \t \t \t ContentValues values = new ContentValues(); \t \t values.put(KEY_EV_NAME,event.get_name()); \t \t values.put(KEY_EV_PASS,event.get_pass()); \t \t values.put(KEY_EV_DATE,event.get_date()); \t \t values.put(KEY_EV_TIME,event.get_time()); \t \t values.put(KEY_EV_ADMIN,event.get_admin()); \t \t \t // \t插入行 \t \t db.insert(TABLE_EVENTS,NULL,值); \t \t db.close(); \t} –