0
我可以編輯&從一個Activity(EditActivity.java)保存數據,但更新的數據不會顯示(或繼續)到下一個Activity(ViewActivity.java )點擊保存按鈕。如果返回到EditActivity頁面,我可以看到EditText字段上的更改。onActivityResult()未從Activity中調用
EditActivity.java
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// starting background task to update request
new SaveRequestDetails().execute();
}
});
class SaveRequestDetails extends AsyncTask<String, String, String> {
protected String doInBackground(String... args) {
// getting updated data from EditTexts
String request_title = txtTitle.getText().toString();
String request_date = txtSdate.getText().toString();
String reqEndDate = txtEdate.getText().toString();
String hours = txtHours.getText().toString();
String reason = txtReason.getText().toString();
String explanation = txtExp.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_ID, request_id));
params.add(new BasicNameValuePair(TAG_TITLE, request_title));
params.add(new BasicNameValuePair(TAG_SDATE, request_date));
params.add(new BasicNameValuePair(TAG_EDATE, reqEndDate));
params.add(new BasicNameValuePair(TAG_HOURS, hours));
params.add(new BasicNameValuePair(TAG_REASON, reason));
params.add(new BasicNameValuePair(TAG_EXP, explanation));
JSONObject json = jsonParser.makeHttpRequest(url_update_request,
"POST", params);
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Intent i = getIntent();
// send result code 100 to notify about request update
setResult(100, i);
finish();
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
ViewActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_request);
Intent i = getIntent();
// getting request id (rid) from intent
request_id = i.getStringExtra(TAG_ID);
// Getting complete request details in background thread
new GetRequestDetails().execute();
btnEdit = (Button) findViewById(R.id.btnEdit);
btnEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Starting new intent
Intent in = new Intent(getApplicationContext(), EditActivity.class);
// sending rid to next activity
in.putExtra(TAG_ID, request_id);
startActivity(in);
}
});
}
// Response from Edit Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted request
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
很好奇 - 爲什麼要刪除此問題[已更新的數據不會顯示在下一個活動屏幕上](http://stackoverflow.com/questions/11782975/updated-data-doesnt-display-on-next-activity-screen?utm_source = twitterfeed&utm_medium = twitter) - deja vu .... Oo – t0mm13b 2012-08-02 19:18:10
以爲我需要刪除它.. ^^ – user1466971 2012-08-02 19:25:27
不用擔心那裏! :)只是我看到了關於Android的問題的推文,並認爲 - 「嗯......這個問題看起來很熟悉」:) – t0mm13b 2012-08-02 20:05:06