EditText數據回顯

首先咱們假設咱們把用戶名和密碼都保存在data/data/com.xxx.xxx/files/info.txt中,格式爲:用戶名##密碼。咱們接下來要作的就是把info.txt中保存的用戶名和密碼分別回顯在兩個EditText中。this

下面爲自定義的回顯用戶名和密碼的方法:spa

public static Map<String,String> getSaveUserInfo(Contextcontext)(){get

Filefile=new File(context.getFilesDir(), 「info.txt」);it

FileInpuStream fis=new FileInpuStream(file);file

BufferReader br=new BufferReader(new FileInpuStream(fis));map

String str=br.readLine();密碼

String infos[]=str.split(「##」);方法

Map<String,String> map=new HashMap<String,String>();static

Map.put(「username」,infos[0]);word

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」));

}

相關文章
相關標籤/搜索