logi登入可记住密码并且显示登入成功
2013-09-12 11:20
351 查看
logi登入可记住密码并且显示登入成功
package com.mxj.login;
importandroid.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public classLogin2Activity extends Activity {
private AutoCompleteTextView user = null;
private EditText password = null;
private CheckBox checkbox = null;
private Button login = null;
private SharedPreferences sp = null;
private String userStr;
private String passwordStr;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
user =(AutoCompleteTextView)super.findViewById(R.id.user);
password =(EditText)super.findViewById(R.id.password);
checkbox =(CheckBox)super.findViewById(R.id.checkbox);
login = (Button)super.findViewById(R.id.login);
sp =this.getSharedPreferences("pwdFile", MODE_PRIVATE);
this.checkbox.setChecked(true);// 默认记住密码
this.user.setThreshold(1);// 输入一个字母就开始提示
password.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);// 隐藏密码获显示密码
user.addTextChangedListener(newTextWatcher() {
publicvoid onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String[] allUserName = new String[sp.getAll().size()];//sp.getAll().size()返回的是有多少个键值对
allUserName = sp.getAll().keySet().toArray(newString[0]);
// sp.getAll()返回一张hash map
// keySet()得到的是a set of the keys.
// hash map是由key-value组成的
ArrayAdapter<String> adapter = newArrayAdapter<String>(
Login2Activity.this,
android.R.layout.simple_dropdown_item_1line,
allUserName);
user.setAdapter(adapter);// 设置数据适配器适配器
}
public void beforeTextChanged(CharSequence s, int start, intcount,
int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
password.setText(sp.getString(user.getText().toString(),""));// 自动输入密码
}
});
// 登录
login.setOnClickListener(new OnClickListener() {
publicvoid onClick(View v) {
// TODO Auto-generated method stub
userStr = user.getText().toString();
passwordStr = password.getText().toString();
if (!((userStr.equals("123")) &&(passwordStr.equals("123")))) {
Toast.makeText(Login2Activity.this, "密码错误,请重新登录",
Toast.LENGTH_SHORT).show();
} else {
if (checkbox.isChecked()) {
sp.edit().putString(userStr,passwordStr).commit();
}
Toast.makeText(Login2Activity.this, "登录成功,正在获取用户数据……",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
-------------------------------------------------------------------------------------------------万恶的下划线--------------------------------------------------------------------------------------------------------------------
<main.xml>
<?xmlversion="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="25sp"
android:text="登录界面" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="帐号:"/>
<AutoCompleteTextView
android:id="@+id/user"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="请输入帐号..."/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="密码:"/>
<EditText
android:id="@+id/password"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="请输入密码..."/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"/>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"/>
</LinearLayout>
< /LinearLayout>
package com.mxj.login;
importandroid.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public classLogin2Activity extends Activity {
private AutoCompleteTextView user = null;
private EditText password = null;
private CheckBox checkbox = null;
private Button login = null;
private SharedPreferences sp = null;
private String userStr;
private String passwordStr;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
user =(AutoCompleteTextView)super.findViewById(R.id.user);
password =(EditText)super.findViewById(R.id.password);
checkbox =(CheckBox)super.findViewById(R.id.checkbox);
login = (Button)super.findViewById(R.id.login);
sp =this.getSharedPreferences("pwdFile", MODE_PRIVATE);
this.checkbox.setChecked(true);// 默认记住密码
this.user.setThreshold(1);// 输入一个字母就开始提示
password.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);// 隐藏密码获显示密码
user.addTextChangedListener(newTextWatcher() {
publicvoid onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String[] allUserName = new String[sp.getAll().size()];//sp.getAll().size()返回的是有多少个键值对
allUserName = sp.getAll().keySet().toArray(newString[0]);
// sp.getAll()返回一张hash map
// keySet()得到的是a set of the keys.
// hash map是由key-value组成的
ArrayAdapter<String> adapter = newArrayAdapter<String>(
Login2Activity.this,
android.R.layout.simple_dropdown_item_1line,
allUserName);
user.setAdapter(adapter);// 设置数据适配器适配器
}
public void beforeTextChanged(CharSequence s, int start, intcount,
int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
password.setText(sp.getString(user.getText().toString(),""));// 自动输入密码
}
});
// 登录
login.setOnClickListener(new OnClickListener() {
publicvoid onClick(View v) {
// TODO Auto-generated method stub
userStr = user.getText().toString();
passwordStr = password.getText().toString();
if (!((userStr.equals("123")) &&(passwordStr.equals("123")))) {
Toast.makeText(Login2Activity.this, "密码错误,请重新登录",
Toast.LENGTH_SHORT).show();
} else {
if (checkbox.isChecked()) {
sp.edit().putString(userStr,passwordStr).commit();
}
Toast.makeText(Login2Activity.this, "登录成功,正在获取用户数据……",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
-------------------------------------------------------------------------------------------------万恶的下划线--------------------------------------------------------------------------------------------------------------------
<main.xml>
<?xmlversion="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="25sp"
android:text="登录界面" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="帐号:"/>
<AutoCompleteTextView
android:id="@+id/user"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="请输入帐号..."/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="密码:"/>
<EditText
android:id="@+id/password"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="请输入密码..."/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"/>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"/>
</LinearLayout>
< /LinearLayout>
相关文章推荐
- 用户输入正确的用户名和密码后,显示登陆成功,并且显示改用户的详细信息。(sqldatasource)
- .做一个登陆的界面,当用户输入正确的用户名和密码后,显示登陆成功,并且显示改用户的详细信息。(sqldatasource)
- 输入密码时显示*并且退格可以删除密码
- 用户登入记住密码案例
- Android生成新的keystore(通过Eclipse的ADT方式)为什么需要输入两个密码,并且第二个密码显示Key certificate validity is required?
- 输入用户名和密码登入到服务器,却显示指定的网络密码不正确,输入了好几次都是这样,这是怎么回事? 用户名和密码没问题 ,一直用的好好地今天就不行了
- JSP成功登录后不让登录名和密码在地址栏中显示
- MiniTwitter登入界面记住密码
- 记住密码的那一刹那显示
- 如何在下次登陆时显示上次成功登陆后的账号的密码
- 记住密码、自动登录、显示密码
- 模拟用户登录情景,并且只能登录三次。(只允许输入三次密码,如果密码正确则提示登录成功,如果三次均输入错误,则退出程序)
- 安卓实现显示记住密码
- 使用cookie设置记住或自动登入登入的用户名和密码
- 编写登录接口,输入用户名密码,认证成功后显示欢迎界面,输错三次后锁定(1.超过三次直接锁定待实现 2.锁定后只能尝试一次)
- 登录界面的记住密码和密码的隐藏、显示
- 【小功能1】android登录时记住和显示密码功能
- 记住密码的那一刹那显示
- 编写代码实现,模拟用户登录情景,并且只能登录三次,只允许输入三次密码,如果密码正确则提示登录成功,如果三次均输入错误,则退出程序。
- Android打造带删除的EditText并且实现输入框密码显示、隐藏