我知道我错过了一些简单的事情。我创建了一个网站管理员,使用SQLite
来跟踪ftp地址,登录详细信息,主目录,网址等。我有一个Activity
,允许用户选择和编辑网站的详细信息。单击按钮会更新数据库中的站点行,但是我无法保存的唯一数据库值是网站远程目录的_remoteHomeDir
var。为什么这个值没有更新?
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;
}
答案 0 :(得分:1)
看起来您正在从edittext siteManHome读取_url和_remoteHomeDir的相同值。这可能是一个错误,可能是您在GUi中有单独的编辑文本
那是:
_url = siteManHome.getText().toString();
_remoteHomeDir = siteManHome.getText().toString();
也许你打算从另一个领域获得_remoteHomeDir
?