我在一个活动中创建动态文本视图,其中一些字段由 Web 服务返回。当用户想要编辑一些数据时,他会被发送到另一个活动。当他单击“后退”按钮时,我想更新上一个活动中的数据,但我不知道正确的做法。我使用 onRestart 方法而不是 onResume
这是我的代码:
我的第一个显示数据的活动:
public class QueryActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.query);
new WSData() {
@Override
public void onPostExecute(final ArrayList<ArrayList<String>> result) { int nbTextView = result.size();
TextView[] textViewArray = new TextView[nbTextView];
for (int i = 0; i < nbTextView; i++) {
// Horizontal Layout to have the accountName and a button to
// edit on the same line
LinearLayout editLayout = new LinearLayout(
QueryActivity.this);
Button edit = new Button(QueryActivity.this);
edit.setBackgroundDrawable(getResources().getDrawable(
R.drawable.editer));
editLayout.removeAllViewsInLayout();
editLayout.setOrientation(LinearLayout.HORIZONTAL);
dynamicWindow.addView(editLayout,
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
textViewArray[i] = new TextView(QueryActivity.this);
// retrieve every field from the result
final String accountId = result.get(i).get(0);
final String accountName = result.get(i).get(1);
final String phone = result.get(i).get(2);
final String industry = result.get(i).get(3);
final String website = result.get(i).get(4);
// display only the accountName
textViewArray[i].setText(accountName);
textViewArray[i].setTextColor(0xFFFFFFFF);
textViewArray[i].setGravity(Gravity.CENTER_VERTICAL);
textViewArray[i].setVisibility(View.VISIBLE);
edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(QueryActivity.this,
EditAccountActivity.class);
startActivity(intent);
}
});
}.execute(sessionName, null, "getAccountInfo");
}
@Override
public void onRestart() {
super.onRestart();
}
我的其他活动,我想在单击“返回”时更新我的数据:
public class EditAccountActivity extends Activity {
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});