/**
* 保存用户信息
* @param number
* @param password
* @return true 成功
*/
public static boolean saveUserInfo(String number, String password) {
try {
String path = "/data/data/com.itheima28.qqlogin/itheima28.txt";
FileOutputStream fos = new FileOutputStream(path);
// 307966990##123123
String data = number + "##" + password;
fos.write(data.getBytes());
fos.flush();
fos.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 返回用户信息
* @return
*/
public static Map<String, String> getUserInfo() {
try {
String path = "/data/data/com.itheima28.qqlogin/itheima28.txt";
FileInputStream fis = new FileInputStream(path);
// 字符流对象
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
// 307966990##123123
String text = reader.readLine();
if(!TextUtils.isEmpty(text)) {
String[] split = text.split("##");
Map<String, String> userInfoMap = new HashMap<String, String>();
userInfoMap.put("number", split[0]);
userInfoMap.put("password", split[1]);
return userInfoMap;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
涉及知识:
android:hint属性 :提示
android:inputType="textPassword"属性:输入类型为密码android:checked:复选框是否选中
查找控件:
findViewById(R.id.***)
一种给按钮加事件的方法
1. btn.setOnClickListener(this);
2. 本类实现 OnClickListener接口,完成 public void onClick(View v);方法。
取出文本:editText1.getText().toString();
判断是否空:TextUtils.isEmpty(String s)
吐司提示:Toast.makeText(this,"文本",Toast.LENGTH_SHORT).show();
checkBox1.isChecked()复选框是否被选中
本应用保存数据的目录
/data/data/包名