保存数据到手机内存

/**
	 * 保存用户信息
	 * @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/包名



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值