我知道我錯過了一些簡單的東西。我做了一個網站管理員,使用SQLite
來跟蹤ftp地址,登錄詳細信息,主目錄,url等。我有一個Activity
,它允許用戶選擇和編輯網站的詳細信息當單擊Update按鈕時,它更新網站的行在數據庫中,但我無法保存的唯一數據庫值是網站遠程目錄的變量_remoteHomeDir
。爲什麼不更新這個值?爲什麼這個字段沒有在SQLLite數據庫中更新?
siteManUpdateBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
_address = siteManFTPAddress.getText().toString();
_username = siteManFTPUsername.getText().toString();
_password = siteManFTPPassword.getText().toString();
String port = siteManFTPPort.getText().toString();
_port = Integer.parseInt(port);
_url = siteManHome.getText().toString();
_remoteHomeDir = siteManHome.getText().toString();
Toast.makeText(SiteManager.this, "Update", Toast.LENGTH_LONG).show();
myDb.updateRow(_rowId, _name, _name, _isLive, _address, _username, _password, _port, _url,_remoteHomeDir);
model.clear();
adapter.notifyDataSetChanged();
displayRecords();
}
});
DBAdapter.java
public boolean updateRow(long rowId, String name, String homedir,
int islive, String address, String username, String password,
int port, String url, String rhome) {
String where = KEY_ROWID + "=" + rowId;
/*
* CHANGE 4:
*/
// TODO: Update data in the row with new fields.
// TODO: Also change the function's arguments to be what you need!
// Create row's data:
ContentValues newValues = new ContentValues();
newValues.put(KEY_NAME, name);
Log.d("tag", "there is something happening here: " + name);
newValues.put(KEY_HOME, homedir);
Log.d("tag", "there is something happening here: " + homedir);
newValues.put(KEY_LIVE, islive);
Log.d("tag", "there is something happening here: " + islive);
newValues.put(KEY_ADDRESS, address);
Log.d("tag", "there is something happening here: " + address);
newValues.put(KEY_USERNAME, username);
Log.d("tag", "there is something happening here: " + username);
newValues.put(KEY_PASSWORD, password);
Log.d("tag", "there is something happening here: " + password);
newValues.put(KEY_PORT, port);
Log.d("tag", "there is something happening here: " + port);
newValues.put(KEY_URL, url);
Log.d("tag", "there is something happening here: " + url);
newValues.put(KEY_RHOME, rhome);
Log.d("tag", "there is something happening here: " + rhome);
// newValues.put(KEY_PASSIVE, passive);
// Insert it into the database.
Log.d("tag", "there is something happening here: " + db.toString());
return db.update(DATABASE_TABLE, newValues, where, null) != 0;
}
檢查你的行ID值,是否有效 –
它必須是如果它適用於每個領域,但一個不是嗎? – RapsFan1981