天天看點

EditText資料回顯

首先我們假設我們把使用者名和密碼都儲存在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”));

繼續閱讀