资源描述:
《android小实例》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、android小实例LoginActivity.java类:packagecom.example.empandroid;importandroid.app.Activity;importandroid.app.ProgressDialog;importandroid.content.Intent;importandroid.database.Cursor;importandroid.os.Bundle;importandroid.text.Editable;importandroid.text.TextWatcher;importandr
2、oid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.Toast;publicclassLoginActivityextendsActivityimplementsOnClickListener{EditTextusername,password;Buttonlogin,register,bt_username_clear,bt_
3、pwd_clear;DBHelperhelper=newDBHelper(this);ProgressDialogm_dlog;privateTextWatcheruname_watcher;privateTextWatcherpwd_watcher;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.login_main);username=(EditText
4、)findViewById(R.id.username);password=(EditText)findViewById(R.id.password);login=(Button)findViewById(R.id.login);register=(Button)findViewById(R.id.register);bt_username_clear=(Button)findViewById(R.id.bt_username_clear);bt_pwd_clear=(Button)findViewById(R.id.bt_pwd_cle
5、ar);login.setOnClickListener(this);register.setOnClickListener(this);bt_username_clear.setOnClickListener(this);bt_pwd_clear.setOnClickListener(this);initWatcher();username.addTextChangedListener(uname_watcher);password.addTextChangedListener(pwd_watcher);}publicvoidinitW
6、atcher(){uname_watcher=newTextWatcher(){@OverridepublicvoidonTextChanged(CharSequencearg0,intarg1,intarg2,intarg3){}@OverridepublicvoidbeforeTextChanged(CharSequencearg0,intarg1,intarg2,intarg3){}@OverridepublicvoidafterTextChanged(Editables){if(s.toString().length()>0){b
7、t_username_clear.setVisibility(View.VISIBLE);}else{bt_username_clear.setVisibility(View.INVISIBLE);}}};pwd_watcher=newTextWatcher(){@OverridepublicvoidonTextChanged(CharSequencearg0,intarg1,intarg2,intarg3){}@OverridepublicvoidbeforeTextChanged(CharSequencearg0,intarg1,in
8、targ2,intarg3){}@OverridepublicvoidafterTextChanged(Editables){if(s.toString().length()>0){bt_pw