有种代码COPY器的感觉!
public class ActionPlanActivity extends Activity {
private EditText et_actionplan11;
private EditText et_actionplan12;
private EditText et_actionplan13;
private EditText et_actionplan14;
private EditText et_actionplan21;
private EditText et_actionplan22;
private EditText et_actionplan23;
private EditText et_actionplan24;
private EditText et_actionplan31;
private EditText et_actionplan32;
private EditText et_actionplan33;
private EditText et_actionplan34;
private EditText et_actionplan_receiver;
private EditText et_actionplan_copytoer;
private EditText et_actionplan_name;
private EditText et_actionplan_job;
private EditText et_actionplan_agencyName;
private EditText et_actionplan_sign;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_actionplan);
init();
}
private void init() {
sp = getSharedPreferences("xdjh", MODE_PRIVATE);
//发音的微油把一阿姨地
et_actionplan11 = (EditText) findViewById(R.id.et_actionplan11);
et_actionplan12 = (EditText) findViewById(R.id.et_actionplan12);
et_actionplan13 = (EditText) findViewById(R.id.et_actionplan13);
et_actionplan14 = (EditText) findViewById(R.id.et_actionplan14);
et_actionplan21 = (EditText) findViewById(R.id.et_actionplan21);
et_actionplan22 = (EditText) findViewById(R.id.et_actionplan22);
et_actionplan23 = (EditText) findViewById(R.id.et_actionplan23);
et_actionplan24 = (EditText) findViewById(R.id.et_actionplan24);
et_actionplan31 = (EditText) findViewById(R.id.et_actionplan31);
et_actionplan32 = (EditText) findViewById(R.id.et_actionplan32);
et_actionplan33 = (EditText) findViewById(R.id.et_actionplan33);
et_actionplan34 = (EditText) findViewById(R.id.et_actionplan34);
et_actionplan_receiver = (EditText) findViewById(R.id.et_actionplan_receiver);
et_actionplan_copytoer = (EditText) findViewById(R.id.et_actionplan_copytoer);
et_actionplan_name = (EditText) findViewById(R.id.et_actionplan_name);
et_actionplan_job = (EditText) findViewById(R.id.et_actionplan_job);
et_actionplan_agencyName = (EditText) findViewById(R.id.et_actionplan_agencyName);
et_actionplan_sign = (EditText) findViewById(R.id.et_actionplan_sign);
//数据回显
et_actionplan11.setText(sp.getString("et_actionplan11", ""));
et_actionplan12.setText(sp.getString("et_actionplan12", ""));
et_actionplan13.setText(sp.getString("et_actionplan13", ""));
et_actionplan14.setText(sp.getString("et_actionplan14", ""));
et_actionplan21.setText(sp.getString("et_actionplan21", ""));
et_actionplan22.setText(sp.getString("et_actionplan22", ""));
et_actionplan23.setText(sp.getString("et_actionplan23", ""));
et_actionplan24.setText(sp.getString("et_actionplan24", ""));
et_actionplan31.setText(sp.getString("et_actionplan31", ""));
et_actionplan32.setText(sp.getString("et_actionplan32", ""));
et_actionplan33.setText(sp.getString("et_actionplan33", ""));
et_actionplan34.setText(sp.getString("et_actionplan34", ""));
et_actionplan_receiver.setText(sp.getString("et_actionplan_receiver", ""));
et_actionplan_copytoer.setText(sp.getString("et_actionplan_copytoer", ""));
et_actionplan_name.setText(sp.getString("et_actionplan_name", ""));
et_actionplan_job.setText(sp.getString("et_actionplan_job", ""));
et_actionplan_name.setText(sp.getString("et_actionplan_name", ""));
et_actionplan_agencyName.setText(sp.getString("et_actionplan_agencyName", ""));
et_actionplan_sign.setText(sp.getString("et_actionplan_sign", ""));
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
//保存当前信息
saveToSp();
break;
}
return super.onKeyDown(keyCode, event);
}
/**
* 保存信息到SP中
*/
private void saveToSp() {
Editor editor = sp.edit();
editor.putString("et_actionplan11", et_actionplan11.getText().toString());
editor.putString("et_actionplan12", et_actionplan12.getText().toString());
editor.putString("et_actionplan13", et_actionplan13.getText().toString());
editor.putString("et_actionplan14", et_actionplan14.getText().toString());
editor.putString("et_actionplan21", et_actionplan21.getText().toString());
editor.putString("et_actionplan22", et_actionplan22.getText().toString());
editor.putString("et_actionplan23", et_actionplan23.getText().toString());
editor.putString("et_actionplan24", et_actionplan24.getText().toString());
editor.putString("et_actionplan31", et_actionplan31.getText().toString());
editor.putString("et_actionplan32", et_actionplan32.getText().toString());
editor.putString("et_actionplan33", et_actionplan33.getText().toString());
editor.putString("et_actionplan34", et_actionplan34.getText().toString());
editor.putString("et_actionplan_receiver", et_actionplan_receiver.getText().toString());
editor.putString("et_actionplan_copytoer", et_actionplan_copytoer.getText().toString());
editor.putString("et_actionplan_name", et_actionplan_name.getText().toString());
editor.putString("et_actionplan_job", et_actionplan_job.getText().toString());
editor.putString("et_actionplan_agencyName", et_actionplan_agencyName.getText().toString());
editor.putString("et_actionplan_sign", et_actionplan_sign.getText().toString());
editor.commit();
}
}
FindViewById
最新推荐文章于 2022-07-13 09:55:17 发布