登录案例:

1)SharedPreferences  的使用

     通过上下文拿到SharedPreferences实例

    SharedPreferences sp=getSharedPreferences("sp",0);

    存入数据:

//获取sp的编辑器                SharedPreferences.Editor edit=sp.edit();                edit.putString("name",name);                edit.putString("pwd",pwd);                //提交编辑器                edit.commit();

    读取数据:

 

 String name=sp.getString("name",""); String pwd=sp.getString("pwd",""); //第一个参数为写入时定义的键,第二个为通过键找不到时的默认值

  注意: 写入时的数据类型和读取时的数据类型要对应

2)☆☆☆☆给CheckBox控件设置是否被选中事件

 cb_ischeck1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {                //判断CheckBox是否被选中                if (cb_ischeck1.isChecked()) {                    /* 设定EditText的内容为可见的 */                    et_password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());                } else {                    /* 设定EditText的内容为隐藏的 */                    et_password.setTransformationMethod(PasswordTransformationMethod.getInstance());                }            }        });

3)☆☆☆☆使用上下文快速获取文件的输入输出流。

String path=context.getFilesDir().getPath();获取地址                File file=new File(path,"info.txt");//通过Context(上下文)获取FileOutputStream FileOutputStream fos=context.openFileOutput("infoo.txt",0); ---第一个参数为新建的文件名第二个为模式0代表私有模式//通过Context(上下文)获取FileInputStreamFileInputStream fis=context.openFileInput("infoo.txt");--参数为要读取的文件

4)

Map的使用创建Map Map masps=new HashMap();向Map中写入数据            String[] splits=content.split("##");  --根据#拆分字符串            String name = splits[0];            String pwd =splits[1];            masps.put("name",name);             masps.put("pwd",pwd);     --把数组中的数据写入Map,名字对应数据从Map中读取数据           Map maps=UserinfoUtils.readInof(MainActivity.this );            String name=maps.get("name");            String pwd=maps.get("pwd");    --把数据从Map中读出,.get(“给数据起的名字”)

5)把数据存入sd卡中

给用户添加sd卡的权限

 

6)获取sd卡的路径

  String sdPath= Environment.getExternalStorageDirectory().getPath();             File file = new File(sdPath,"ha.txt");

7)判断sd卡是否可用

Environment.getExternalStorageState()  获取sd卡当前状态
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){                    Toast.makeText(MainActivity.this,"sd卡可用",Toast.LENGTH_LONG).show();                }else{                    Toast.makeText(MainActivity.this,"sd卡不可用",Toast.LENGTH_LONG).show();                }

8)获取sd卡的可用空间和总空间

 

更多相关文章

  1. Android(安卓)jni 编程(参数的传递,成员,方法的)相互访问
  2. Android(安卓)保存图片到SQLite
  3. (Android) ContentProvider 实例
  4. android 利用pull解析xml数据
  5. Android:week 11总结 内容提供者、数据库
  6. 下拉菜单中自动亮度调节&P 上背光调节
  7. Android(安卓)数据库SQLite的使用简单Demo
  8. Android(安卓)-- 跨应用启动Service
  9. android http请求访问接口的封装

随机推荐

  1. Unable to execute dex: java.nio.Buffer
  2. android 状态栏显示运行图标
  3. Android(安卓)之ContextMenu上下文菜单
  4. HTML5 Cache, Android(安卓)WebView
  5. Android(安卓)动态获取资源ID
  6. Android(安卓)- ImageView 加边框 实例
  7. Android(安卓)InputMethodManager泄漏Act
  8. android中的定时任务AlarmManager
  9. Android(安卓)Splash Activity Demo
  10. android listview 调用sqlsite数据库显示