iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android中怎么使用SQLite实现记住密码功能
  • 458
分享到

Android中怎么使用SQLite实现记住密码功能

androidsqlite 2023-05-31 00:05:13 458人浏览 独家记忆
摘要

这期内容当中小编将会给大家带来有关Android中怎么使用sqlite实现记住密码功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。具体内容如下package com.example.alimj

这期内容当中小编将会给大家带来有关Android中怎么使用sqlite实现记住密码功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

具体内容如下

package com.example.alimjan.hello_world;  import com.example.alimjan.hello_world.bean.UserInfo;  import com.example.alimjan.hello_world.dataBase.UserDBHelper;  import com.example.alimjan.hello_world.Utils.DateUtil;  import android.app.AlertDialog;  import android.content.Context;  import android.content.DialogInterface;  import android.content.Intent;  import android.os.Bundle;  import android.support.v7.app.AppCompatActivity;  import android.text.Editable;  import android.text.TextWatcher;  import android.util.Log;  import android.view.View;  import android.view.View.OnClickListener;  import android.view.View.OnFocusChangeListener;  import android.widget.AdapterView;  import android.widget.ArrayAdapter;  import android.widget.Button;  import android.widget.CheckBox;  import android.widget.CompoundButton;  import android.widget.EditText;  import android.widget.RadioButton;  import android.widget.RadioGroup;  import android.widget.Spinner;  import android.widget.TextView;  import android.widget.Toast;  import android.widget.AdapterView.OnItemSelectedListener;public class class_4_2_3 extends AppCompatActivity implements OnClickListener, OnFocusChangeListener { private RadioGroup rg_login; private RadioButton rb_passWord; private RadioButton rb_verifycode; private EditText et_phone; private TextView tv_password; private EditText et_password; private Button btn_forget; private CheckBox ck_remember; private Button btn_login; private int mRequestCode = 0; private int mType = 0; private boolean bRemember = false; private String mPassword = "111111"; private String mVerifyCode; private UserDBHelper mHelper; @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.code_4_2_3);  rg_login = (RadioGroup) findViewById(R.id.rg_login);  rb_password = (RadioButton) findViewById(R.id.rb_password);  rb_verifycode = (RadioButton) findViewById(R.id.rb_verifycode);  et_phone = (EditText) findViewById(R.id.et_phone);  tv_password = (TextView) findViewById(R.id.tv_password);  et_password = (EditText) findViewById(R.id.et_password);  btn_forget = (Button) findViewById(R.id.btn_forget);  ck_remember = (CheckBox) findViewById(R.id.ck_remember);  btn_login = (Button) findViewById(R.id.btn_login);  rg_login.setOnCheckedChangeListener(new RadioListener());  ck_remember.setOnCheckedChangeListener(new CheckListener());  et_phone.addTextChangedListener(new HideTextWatcher(et_phone));  et_password.addTextChangedListener(new HideTextWatcher(et_password));  btn_forget.setOnClickListener(this);  btn_login.setOnClickListener(this);  et_password.setOnFocusChangeListener(this);  ArrayAdapter<String> typeAdapter = new ArrayAdapter<String>(this,    R.layout.item_select, typeArray);  typeAdapter.setDropDownViewResource(R.layout.item_dropdown);  Spinner sp_type = (Spinner) findViewById(R.id.sp_type);  sp_type.setPrompt("请选择用户类型");  sp_type.setAdapter(typeAdapter);  sp_type.setSelection(mType);  sp_type.setOnItemSelectedListener(new TypeSelectedListener()); } private class RadioListener implements RadioGroup.OnCheckedChangeListener {  @Override  public void onCheckedChanged(RadioGroup group, int checkedId) {   if (checkedId == R.id.rb_password) {    tv_password.setText("登录密码:");    et_password.setHint("请输入密码");    btn_forget.setText("忘记密码");    ck_remember.setVisibility(View.VISIBLE);   } else if (checkedId == R.id.rb_verifycode) {    tv_password.setText(" 验证码:");    et_password.setHint("请输入验证码");    btn_forget.setText("获取验证码");    ck_remember.setVisibility(View.INVISIBLE);   }  } } private String[] typeArray = {"个人用户", "公司用户"}; class TypeSelectedListener implements OnItemSelectedListener {  public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {   mType = arg2;  }  public void onNothingSelected(AdapterView<?> arg0) {  } } private class CheckListener implements CompoundButton.OnCheckedChangeListener {  @Override  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {   if (buttonView.getId() == R.id.ck_remember) {    bRemember = isChecked;   }  } } private class HideTextWatcher implements TextWatcher {  private EditText mView;  private int mMaxLength;  private CharSequence mStr;  public HideTextWatcher(EditText v) {   super();   mView = v;   mMaxLength = ViewUtil.getMaxLength(v);  }  @Override  public void beforeTextChanged(CharSequence s, int start, int count, int after) {  }  @Override  public void onTextChanged(CharSequence s, int start, int before, int count) {   mStr = s;  }  @Override  public void afterTextChanged(Editable s) {   if (mStr == null || mStr.length() == 0)    return;   if ((mStr.length() == 11 && mMaxLength == 11) ||     (mStr.length() == 6 && mMaxLength == 6)) {    ViewUtil.hideOneInputMethod(class_4_2_3.this, mView);   }  } } @Override public void onClick(View v) {  String phone = et_phone.getText().toString();  if (v.getId() == R.id.btn_forget) {   if (phone==null || phone.length()<11) {    Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();    return;   }   if (rb_password.isChecked() == true) {    Intent intent = new Intent(this, class_4_2_3_1.class);    intent.putExtra("phone", phone);    startActivityForResult(intent, mRequestCode);   } else if (rb_verifycode.isChecked() == true) {    mVerifyCode = String.fORMat("%06d", (int)(Math.random()*1000000%1000000));    AlertDialog.Builder builder = new AlertDialog.Builder(this);    builder.setTitle("请记住验证码");    builder.setMessage("手机号"+phone+",本次验证码是"+mVerifyCode+",请输入验证码");    builder.setPositiveButton("好的", null);    AlertDialog alert = builder.create();    alert.show();   }  } else if (v.getId() == R.id.btn_login) {   if (phone==null || phone.length()<11) {    Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();    return;   }   if (rb_password.isChecked() == true) {    if (et_password.getText().toString().equals(mPassword) != true) {     Toast.makeText(this, "请输入正确的密码", Toast.LENGTH_SHORT).show();     return;    } else {     loginSuccess();    }   } else if (rb_verifycode.isChecked() == true) {    if (et_password.getText().toString().equals(mVerifyCode) != true) {     Toast.makeText(this, "请输入正确的验证码", Toast.LENGTH_SHORT).show();     return;    } else {     loginSuccess();    }   }  } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {  if (requestCode == mRequestCode && data!=null) {   //用户密码已改为新密码   mPassword = data.getStringExtra("new_password");  } } //从修改密码页面返回登录页面,要清空密码的输入框 @Override protected void onRestart() {  et_password.setText("");  super.onRestart(); } @Override protected void onResume() {  super.onResume();  mHelper = UserDBHelper.getInstance(this, 2);  mHelper.openWriteLink(); } @Override protected void onPause() {  super.onPause();  mHelper.closeLink(); } private void loginSuccess() {  String desc = String.format("您的手机号码是%s,类型是%s。恭喜你通过登录验证,点击“确定”按钮返回上个页面",    et_phone.getText().toString(), typeArray[mType]);  AlertDialog.Builder builder = new AlertDialog.Builder(this);  builder.setTitle("登录成功");  builder.setMessage(desc);  builder.setPositiveButton("确定返回", new DialogInterface.OnClickListener() {   @Override   public void onClick(DialogInterface dialog, int which) {    finish();   }  });  builder.setNegativeButton("我再看看", null);  AlertDialog alert = builder.create();  alert.show();  if (bRemember) {   UserInfo info = new UserInfo();   info.phone = et_phone.getText().toString();   info.password = et_password.getText().toString();   info.update_time = DateUtil.getCurDateStr("yyyy-MM-dd HH:mm:ss");   mHelper.insert(info);  } } //为什么光标进入密码框事件不选onClick?因为要点两下才会触发onClick动作(第一下是切换焦点动作) @Override public void onFocusChange(View v, boolean hasFocus) {  String phone = et_phone.getText().toString();  if (v.getId() == R.id.et_password) {   if (phone.length() > 0 && hasFocus == true) {    UserInfo info = mHelper.queryByPhone(phone);    if (info != null) {     et_password.setText(info.password);    }else{     et_password.setText("");    }   }  } } public static void startHome(Context mContext) {  Intent intent = new Intent(mContext, class_4_2_3.class);  mContext.startActivity(intent); }}
<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" android:focusableInTouchMode="true" android:orientation="vertical" android:padding="5dp" > <RadioGroup  android:id="@+id/rg_login"  android:layout_width="match_parent"  android:layout_height="60dp"  android:orientation="horizontal" >  <RadioButton   android:id="@+id/rb_password"   android:layout_width="0dp"   android:layout_height="match_parent"   android:layout_weight="1"   android:checked="true"   android:gravity="left|center"   android:text="密码登录"   android:textColor="@color/black"   android:textSize="17sp" />  <RadioButton   android:id="@+id/rb_verifycode"   android:layout_width="0dp"   android:layout_height="match_parent"   android:layout_weight="1"   android:checked="false"   android:gravity="left|center"   android:text="验证码登录"   android:textColor="@color/black"   android:textSize="17sp" /> </RadioGroup> <RelativeLayout  android:layout_width="match_parent"  android:layout_height="60dp" >  <TextView   android:id="@+id/tv_type"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_alignParentLeft="true"   android:gravity="center"   android:text="  我是:"   android:textColor="@color/black"   android:textSize="17sp" />  <Spinner   android:id="@+id/sp_type"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_toRightOf="@+id/tv_type"   android:gravity="left|center"   android:spinnerMode="dialog" /> </RelativeLayout> <RelativeLayout  android:layout_width="match_parent"  android:layout_height="60dp" >  <TextView   android:id="@+id/tv_phone"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_alignParentLeft="true"   android:gravity="center"   android:text="手机号码:"   android:textColor="@color/black"   android:textSize="17sp" />  <EditText   android:id="@+id/et_phone"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_marginBottom="5dp"   android:layout_marginTop="5dp"   android:layout_toRightOf="@+id/tv_phone"   android:background="@drawable/editext_selector"   android:gravity="left|center"   android:hint="请输入手机号码"   android:inputType="number"   android:maxLength="11"   android:textColor="@color/black"   android:textColorHint="@color/grey"   android:textCursorDrawable="@drawable/text_cursor"   android:textSize="17sp" /> </RelativeLayout> <RelativeLayout  android:layout_width="match_parent"  android:layout_height="60dp" >  <TextView   android:id="@+id/tv_password"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_alignParentLeft="true"   android:gravity="center"   android:text="登录密码:"   android:textColor="@color/black"   android:textSize="17sp" />  <FrameLayout   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_toRightOf="@+id/tv_password" >   <EditText    android:id="@+id/et_password"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:layout_marginBottom="5dp"    android:layout_marginTop="5dp"    android:background="@drawable/editext_selector"    android:gravity="left|center"    android:hint="请输入密码"    android:inputType="numberPassword"    android:maxLength="6"    android:textColor="@color/black"    android:textColorHint="@color/grey"    android:textCursorDrawable="@drawable/text_cursor"    android:textSize="17sp" />   <Button    android:id="@+id/btn_forget"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:layout_gravity="right"    android:gravity="center"    android:text="忘记密码"    android:textColor="@color/black"    android:textSize="17sp" />  </FrameLayout> </RelativeLayout> <CheckBox  android:id="@+id/ck_remember"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:button="@drawable/checkbox_selector"  android:checked="false"  android:padding="10dp"  android:text="记住密码"  android:textColor="@color/black"  android:textSize="17sp" /> <Button  android:id="@+id/btn_login"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:text="登录"  android:textColor="@color/black"  android:textSize="22sp" /></LinearLayout>

Android中怎么使用SQLite实现记住密码功能

package com.example.alimjan.hello_world;  import android.app.Activity;  import android.app.AlertDialog;  import android.content.Context;  import android.content.Intent;  import android.os.Bundle;  import android.support.v7.app.AppCompatActivity;  import android.view.View;  import android.view.View.OnClickListener;  import android.widget.EditText;  import android.widget.Toast;public class class_4_2_3_1 extends AppCompatActivity implements OnClickListener { private EditText et_password_first; private EditText et_password_second; private EditText et_verifycode; private String mVerifyCode; private String mPhone; @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.code_4_2_3_1);  et_password_first = (EditText) findViewById(R.id.et_password_first);  et_password_second = (EditText) findViewById(R.id.et_password_second);  et_verifycode = (EditText) findViewById(R.id.et_verifycode);  findViewById(R.id.btn_verifycode).setOnClickListener(this);  findViewById(R.id.btn_confirm).setOnClickListener(this);  mPhone = getIntent().getStringExtra("phone"); } @Override public void onClick(View v) {  if (v.getId() == R.id.btn_verifycode) {   if (mPhone==null || mPhone.length()<11) {    Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();    return;   }   mVerifyCode = String.format("%06d", (int) (Math.random() * 1000000 % 1000000));   AlertDialog.Builder builder = new AlertDialog.Builder(this);   builder.setTitle("请记住验证码");   builder.setMessage("手机号"+mPhone+",本次验证码是"+mVerifyCode+",请输入验证码");   builder.setPositiveButton("好的", null);   AlertDialog alert = builder.create();   alert.show();  } else if (v.getId() == R.id.btn_confirm) {   String password_first = et_password_first.getText().toString();   String password_second = et_password_second.getText().toString();   if (password_first==null || password_first.length()<6 ||     password_second==null || password_second.length()<6) {    Toast.makeText(this, "请输入正确的新密码", Toast.LENGTH_SHORT).show();    return;   }   if (password_first.equals(password_second) != true) {    Toast.makeText(this, "两次输入的新密码不一致", Toast.LENGTH_SHORT).show();    return;   }   if (et_verifycode.getText().toString().equals(mVerifyCode) != true) {    Toast.makeText(this, "请输入正确的验证码", Toast.LENGTH_SHORT).show();    return;   } else {    Toast.makeText(this, "密码修改成功", Toast.LENGTH_SHORT).show();    Intent intent = new Intent();    intent.putExtra("new_password", password_first);    setResult(Activity.RESULT_OK, intent);    finish();   }  } } public static void startHome(Context mContext) {  Intent intent = new Intent(mContext, class_4_2_3_1.class);  mContext.startActivity(intent); }}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" android:focusableInTouchMode="true" android:orientation="vertical" android:padding="5dp" > <RelativeLayout  android:layout_width="match_parent"  android:layout_height="60dp" >  <TextView   android:id="@+id/tv_password_first"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_alignParentLeft="true"   android:gravity="center"   android:text="输入新密码:"   android:textColor="@color/black"   android:textSize="17sp" />  <EditText   android:id="@+id/et_password_first"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_marginBottom="5dp"   android:layout_marginTop="5dp"   android:layout_toRightOf="@+id/tv_password_first"   android:background="@drawable/editext_selector"   android:gravity="left|center"   android:hint="请输入新密码"   android:inputType="numberPassword"   android:maxLength="11"   android:textColor="@color/black"   android:textColorHint="@color/grey"   android:textCursorDrawable="@drawable/text_cursor"   android:textSize="17sp" /> </RelativeLayout> <RelativeLayout  android:layout_width="match_parent"  android:layout_height="60dp" >  <TextView   android:id="@+id/tv_password_second"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_alignParentLeft="true"   android:gravity="center"   android:text="确认新密码:"   android:textColor="@color/black"   android:textSize="17sp" />  <EditText   android:id="@+id/et_password_second"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_marginBottom="5dp"   android:layout_marginTop="5dp"   android:layout_toRightOf="@+id/tv_password_second"   android:background="@drawable/editext_selector"   android:gravity="left|center"   android:hint="请再次输入新密码"   android:inputType="numberPassword"   android:maxLength="11"   android:textColor="@color/black"   android:textColorHint="@color/grey"   android:textCursorDrawable="@drawable/text_cursor"   android:textSize="17sp" /> </RelativeLayout> <RelativeLayout  android:layout_width="match_parent"  android:layout_height="60dp" >  <TextView   android:id="@+id/tv_verifycode"   android:layout_width="wrap_content"   android:layout_height="match_parent"   android:layout_alignParentLeft="true"   android:gravity="center"   android:text="  验证码:"   android:textColor="@color/black"   android:textSize="17sp" />  <FrameLayout   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_toRightOf="@+id/tv_verifycode" >   <EditText    android:id="@+id/et_verifycode"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:layout_marginBottom="5dp"    android:layout_marginTop="5dp"    android:background="@drawable/editext_selector"    android:gravity="left|center"    android:hint="请输入验证码"    android:inputType="numberPassword"    android:maxLength="6"    android:textColor="@color/black"    android:textColorHint="@color/grey"    android:textCursorDrawable="@drawable/text_cursor"    android:textSize="17sp" />   <Button    android:id="@+id/btn_verifycode"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:layout_gravity="right"    android:gravity="center"    android:text="获取验证码"    android:textColor="@color/black"    android:textSize="17sp" />  </FrameLayout> </RelativeLayout> <Button  android:id="@+id/btn_confirm"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:text="确定"  android:textColor="@color/black"  android:textSize="22sp" /></LinearLayout>

上述就是小编为大家分享的Android中怎么使用SQLite实现记住密码功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程网精选频道。

--结束END--

本文标题: Android中怎么使用SQLite实现记住密码功能

本文链接: https://www.lsjlt.com/news/222396.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • C++ 生态系统中流行库和框架的贡献指南
    作为 c++++ 开发人员,通过遵循以下步骤即可为流行库和框架做出贡献:选择一个项目并熟悉其代码库。在 issue 跟踪器中寻找适合初学者的问题。创建一个新分支,实现修复并添加测试。提交...
    99+
    2024-05-15
    框架 c++ 流行库 git
  • C++ 生态系统中流行库和框架的社区支持情况
    c++++生态系统中流行库和框架的社区支持情况:boost:活跃的社区提供广泛的文档、教程和讨论区,确保持续的维护和更新。qt:庞大的社区提供丰富的文档、示例和论坛,积极参与开发和维护。...
    99+
    2024-05-15
    生态系统 社区支持 c++ overflow 标准库
  • c++中if elseif使用规则
    c++ 中 if-else if 语句的使用规则为:语法:if (条件1) { // 执行代码块 1} else if (条件 2) { // 执行代码块 2}// ...else ...
    99+
    2024-05-15
    c++
  • c++中的继承怎么写
    继承是一种允许类从现有类派生并访问其成员的强大机制。在 c++ 中,继承类型包括:单继承:一个子类从一个基类继承。多继承:一个子类从多个基类继承。层次继承:多个子类从同一个基类继承。多层...
    99+
    2024-05-15
    c++
  • c++中如何使用类和对象掌握目标
    在 c++ 中创建类和对象:使用 class 关键字定义类,包含数据成员和方法。使用对象名称和类名称创建对象。访问权限包括:公有、受保护和私有。数据成员是类的变量,每个对象拥有自己的副本...
    99+
    2024-05-15
    c++
  • c++中优先级是什么意思
    c++ 中的优先级规则:优先级高的操作符先执行,相同优先级的从左到右执行,括号可改变执行顺序。操作符优先级表包含从最高到最低的优先级列表,其中赋值运算符具有最低优先级。通过了解优先级,可...
    99+
    2024-05-15
    c++
  • c++中a+是什么意思
    c++ 中的 a+ 运算符表示自增运算符,用于将变量递增 1 并将结果存储在同一变量中。语法为 a++,用法包括循环和计数器。它可与后置递增运算符 ++a 交换使用,后者在表达式求值后递...
    99+
    2024-05-15
    c++
  • c++中a.b什么意思
    c++kquote>“a.b”表示对象“a”的成员“b”,用于访问对象成员,可用“对象名.成员名”的语法。它还可以用于访问嵌套成员,如“对象名.嵌套成员名.成员名”的语法。 c++...
    99+
    2024-05-15
    c++
  • C++ 并发编程库的优缺点
    c++++ 提供了多种并发编程库,满足不同场景下的需求。线程库 (std::thread) 易于使用但开销大;异步库 (std::async) 可异步执行任务,但 api 复杂;协程库 ...
    99+
    2024-05-15
    c++ 并发编程
  • 如何在 Golang 中备份数据库?
    在 golang 中备份数据库对于保护数据至关重要。可以使用标准库中的 database/sql 包,或第三方包如 github.com/go-sql-driver/mysql。具体步骤...
    99+
    2024-05-15
    golang 数据库备份 mysql git 标准库
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作