FindViewById

有种代码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();
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值