package com.learn.sd2;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.EditText;
public class mainm extends Activity {
private EditText t1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t1=(EditText) findViewById(R.id.EditText01);
String string1;
SharedPreferences store=getSharedPreferences(“storexml”,0);//建立storexml.xml
string1=store.getString(“row1″, “”);//从storexml.xml中读取上次进度,存到string1中
t1.setText(string1);//把上次进度显示在屏幕
}
protected void onStop() {
super.onStop();
SharedPreferences store=getSharedPreferences(“storexml”,0);
SharedPreferences.Editor editor=store.edit();
editor.putString(“row1″, t1.getText().toString());
editor.commit();
}
}
用SharedPreferences存储数据,一个最简单的例子
最新推荐文章于 2019-05-23 21:03:41 发布