登录中用于记住用户名和密码的方法

2024-06-07 10:58

本文主要是介绍登录中用于记住用户名和密码的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

public abstract class ADtLoginActivity extends ADtBaseActivity
{


    private EditText mTextUserName;
    private EditText mTextPassWord;
    private CheckBox mCheckBox;
    private SharedPreferences mSharedPreferences;
     //保存记住的用户名和密码
    String saveUserName;
    String savePassWord;
    Editor editor;


    @Override
    protected int getLayoutId()
    {
        return R.layout.login;
    }


    @Override
    protected void onLoadView()
    {
        mTextUserName = findEditTextById(R.id.edit_txt_user_name);
        mTextPassWord = findEditTextById(R.id.edit_txt_password);
    }


    @Override
    protected void onLoadContent()
    {
        ((ImageButton) findViewById(R.id.btn_title_left)).setImageResource(R.drawable.btn_back);
        ((ImageButton) findViewById(R.id.btn_title_left)).setOnClickListener(this);
        findViewById(R.id.btn_title_right).setVisibility(View.INVISIBLE);
        ((TextView) findViewById(R.id.txt_title)).setText("登陆");
         mCheckBox=(CheckBox)findViewById(R.id.cb_remember_password);
         mSharedPreferences=getSharedPreferences("remember_password",MODE_PRIVATE);
         saveUserName=mSharedPreferences.getString("username", null);
         savePassWord=mSharedPreferences.getString("password",null);
 
        if (savePassWord!=null&&saveUserName!=null) {
            mCheckBox.setChecked(true);
            mTextUserName.setText(saveUserName);
            mTextPassWord.setText(savePassWord);
        }
    }
    @Override
    protected void onLoadBind()
    {
        findButtonById(R.id.btn_register).setOnClickListener(this);
        findButtonById(R.id.btn_login).setOnClickListener(this);
        findButtonById(R.id.btn_reset).setOnClickListener(this);
        findViewById(R.id.btn_qq_login_on).setOnClickListener(this);
        findViewById(R.id.btn_sina_login_on).setOnClickListener(this);
    }


    @Override
    protected void onClick(View v, int id)
    {
        if (id == R.id.btn_title_left)
        {
           this.finish();


        } else if (id == R.id.btn_register)
        {
            onBtnRegister();
        } else if (id == R.id.btn_login)
        {
            //1、获取SharePrefernce里面保存的用户名和密码
            editor = mSharedPreferences.edit();
            if (mCheckBox.isChecked())
            {
                //2、保存用户名和密码在shareprerence
                editor.putString("username", mTextUserName.getText().toString().trim());
                editor.putString("password", mTextPassWord.getText().toString().trim());
                editor.commit();
                onBtnLogin(mTextUserName.getText().toString().trim(), mTextPassWord.getText().toString().trim());
                mCheckBox.setChecked(true);
            }else if (savePassWord!=null&&savePassWord!=null){
                //editor=mSharedPreferences.edit();
                editor.putString("username",null).commit();
                editor.putString("password",null).commit();
                 mCheckBox.setChecked(false);
            }
               onBtnLogin(mTextUserName.getText().toString().trim(), mTextPassWord.getText().toString().trim());


        } else if (id == R.id.btn_reset)
        {
            onBtnResetPassword();


        } else if (id == R.id.btn_sina_login_on)
        {
            onSinaLogin();
        }  else if (id==R.id.btn_qq_login_on);
        {
            onQQLogin();
        }
    }


    protected abstract void onBtnRegister();


    protected abstract void onBtnLogin(String userName, String passWord);


    protected abstract void onBtnResetPassword();


    protected abstract void onQQLogin();


    protected abstract void onSinaLogin();

这篇关于登录中用于记住用户名和密码的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1038988

相关文章

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows

判断PyTorch是GPU版还是CPU版的方法小结

《判断PyTorch是GPU版还是CPU版的方法小结》PyTorch作为当前最流行的深度学习框架之一,支持在CPU和GPU(NVIDIACUDA)上运行,所以对于深度学习开发者来说,正确识别PyTor... 目录前言为什么需要区分GPU和CPU版本?性能差异硬件要求如何检查PyTorch版本?方法1:使用命

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Java中的工具类命名方法

《Java中的工具类命名方法》:本文主要介绍Java中的工具类究竟如何命名,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java中的工具类究竟如何命名?先来几个例子几种命名方式的比较到底如何命名 ?总结Java中的工具类究竟如何命名?先来几个例子JD

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen