首先我们假设我们把用户名和密码都保存在data/data/com.xxx.xxx/files/info.txt中,格式为:用户名##密码。我们接下来要做的就是把info.txt中保存的用户名和密码分别回显在两个edittext中。
下面为自定义的回显用户名和密码的方法:
public static map<string,string> getsaveuserinfo(contextcontext)(){
filefile=new file(context.getfilesdir(), “info.txt”);
fileinpustream fis=new fileinpustream(file);
bufferreader br=new bufferreader(new fileinpustream(fis));
string str=br.readline();
string infos[]=str.split(“##”);
map<string,string> map=new hashmap<string,string>();
map.put(“username”,infos[0]);
map.put(“password”,infos[1]);
return map;
}
方法定义好了,接下来就是在需要的位置调用了:
map<string,string> map=getsaveuserinfo(this);
if(map!=null){
myedittext1.settext(map.get(“username”));
myedittext2.settext(map.get(“password”));