首先,我有一個在rails上使用Ruby創建的數據庫。 我剛剛在我的Android應用程序中實現了插入函數(HTTPPost),它的工作。 但我不知道如何從我的數據庫中檢索特定的記錄,並在Android中插回特定記錄(如在回報率編輯功能)Android:如何在Android編程中編輯數據庫中的特定記錄(在rails上使用Ruby)
這是我的插入代碼:
私人無效insertComment() DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://10.10.3.87:3000/comments");
// Configure the form parameters
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("comment[content]", t_comment.getText().toString()));
nvps.add(new BasicNameValuePair("comment[id_account]", "1"));
nvps.add(new BasicNameValuePair("comment[id_place]", Integer.toString(position)));
try {
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpResponse response = null;
try {
response = client.execute(post);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try {
entity.consumeContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Toast.makeText(this, "Your post is successfully uploaded",
Toast.LENGTH_SHORT).show();
t_comment.setText("");
}
我真的嘗試了很多方法,但它不起作用,並且需要很長時間來處理這段代碼。其實,我真的不知道如何指定RowID到HTTPPost。
任何人都可以幫助我嗎? 在此先感謝
BTW您的幫助^^______________很多,使用Rails的最新版本我認爲定義動作的XML觀點,與在適當的地方.xml擴展名創建一個文件一樣簡單並用XML內容填充它。例如,如果你已經有app/views/comments/show.html。erb你會創建app/views/comments/show.xml並填充一些XML,如「「><%= @ comment.content%> 」。 –
2010-01-05 17:48:35