android保存配置文档
public class Test extends Activity implements OnClickListener {
private EditText etName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
etName = (EditText) findViewById(R.id.etName);
Button btnLoad = (Button) findViewById(R.id.btnLoad);
Button btnSave = (Button) findViewById(R.id.btnSave);
btnLoad.setOnClickListener(this);
btnSave.setOnClickListener(this);
}
@Override
public void onClick(View v) {
SharedPreferences pre = Test.this.getSharedPreferences("hfgis",
Context.MODE_PRIVATE);
switch (v.getId()) {
case R.id.btnLoad:
etName.setText(pre.getString("account", "加载失败!"));
break;
case R.id.btnSave:
Editor ed = pre.edit();
String str = etName.getText().toString().trim();
ed.putString("current", str);
ed.commit();
break;
default:
break;
}
}
}
摘自 oldfeel
补充:移动开发 , Android ,