登录保存多个账号密码

废话不多时说直接上代码

登录成功保存证号密码

  public void lodg() {

        helper = new SharedPreferencesHelper(context, "user");
        map = (Map) helper.getAll();


        for (int i = 0; i < map.size(); i++) {
            String name = (String) helper.getSharedPreference("name" + i, "");
            String pwd = (String) helper.getSharedPreference("pwd" + i, "");
            int pwd1 = (int) helper.getSharedPreference("pwd1" + i, 0);
            if (!name.equals("") && !pwd.equals("")) {

                list.add(new UserData(name, pwd,pwd1));
            }
        }


    }

每次进入获取SharedPreferencesHelper保存的数据

  helper = new SharedPreferencesHelper(context, "user");
        map = (Map) helper.getAll();


        for (int i = 0; i < map.size(); i++) {
            String name = (String) helper.getSharedPreference("name" + i, "");
            String pwd = (String) helper.getSharedPreference("pwd" + i, "");
            int pwd1 = (int) helper.getSharedPreference("pwd1" + i, 0);
            if (!name.equals("") && !pwd.equals("")) {

                list.add(new UserData(name, pwd,pwd1));
            }
        }

对话框的展示数据

   adapter = new Lingondadaper(context, list, null);
                option = getLayoutInflater().inflate(R.layout.simple_item, null);
                // 要在这个linearLayout里面找listView......
                listView = (ListView) option.findViewById(R.id.lv);
                listView.setAdapter(adapter);
                listView.setOnItemClickListener(this);

                ColorDrawable dw = new ColorDrawable(0000000000);
                // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作


                //实例化一个popupwindow对象
                pw = new PopupWindow(option, etPhone.getWidth(), WindowManager.LayoutParams.WRAP_CONTENT, true);
                pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_radius15_gray));
                pw.setOutsideTouchable(true);
                pw.setBackgroundDrawable(dw);
                pw.showAsDropDown(Rl, 0, 0);

 

你可能感兴趣的:(登录保存多个账号密码)