版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Android手机通用登陆界面代码设计在众多应用中,登陆界面是很多软件不可缺少的部分。本登陆界面使用SQLite设计数据库,便于与其他需求接口,下面分文件列出全部代码,欢迎指正。/DataBaseHelper.java数据库文件importandroid.content.Context;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteDatabase.CursorFactory;importandroid.database.sqlite.SQLiteOpenHelper;impor
2、tandroid.util.Log;publicclassDataBaseHelperextendsSQLiteOpenHelperpublicDataBaseHelper(Contextcontext,Stringname,CursorFactoryfactory,intversion)super(context,name,factory,version);OverridepublicvoidonCreate(SQLiteDatabase_db)_db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE);OverridepublicvoidonUpgr
3、ade(SQLiteDatabase_db,int_oldVersion,int_newVersion)Log.wCTaskDBAdapter蔦Upgradingfromversion+_oldVersion+to+_newVersion+,whichwilldestroyallolddata11);_dbexecSQLDROPTABLEIFEXISTS+“TEMPLATEJ;onCreate(_db);/HomeActivity,java主界面程序文件importandroid.app.Activity;importandroid.app.Dialog;importandroid.conte
4、ntntent;importandroid.os.Bundie;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.Toast;publicclassHomeActivityextendsActivityButtonbtnSignln,btnSignUp;LoginDataBaseAdapterloginDataBaseAdapter;OverrideprotectedvoidonCreate(BundlesavedlnstanceState
5、)super.onCreate(savedlnstanceState);setContentView(Rayout.main);/createainstanceofSQLiteDatabaseloginDataBaseAdapter二newLoginDataBaseAdapter(this);loginDataBaseAdapter=loginDataBaseAdapter.open();/GetTheRefferenceOfButtonsbtnSignln=(Button)findViewByld(R.id.buttonSignlN);btnSignllp=(Button)findViewB
6、yld(R.id.buttonSignUP);/SetOnClickListeneronSignUpbuttonbtnSignllp.setOnClickListener(newView.OnClickListener()publicvoidonClick(Viewv)/TODOAuto-generatedmethodstubIIICreateIntentforSignllpActivityandStartTheActivityIntentintentSignllP=newIntent(getApplicationContext()”SignUPActivity.class);startAct
7、ivity(intentSignllP););/MethostohandleClickEventofSignInButtonpublicvoidsignln(ViewV)finalDialogdialog=newDialog(HomeActivity.this);dialog.setContentView(R.layout.login);dialog.setTitle(,Login);/gettheRefferencesofviewsfinalEditTexteditTextUserName=(EditText)dialog.findViewByld(R.id.editTextUserName
8、ToLogin);finalEditTexteditTextPassword=(EditText)dialog.findViewByld(R.id.editTextPasswordToLogin);ButtonbtnSignln=(Button)dialog.findViewByld(R.id.buttonSignln);btnSignln.setOnClickListener(newView.OnClickListener()publicvoidonClick(Viewv)StringuserName=editTextUserName.getText().toString();Stringp
9、assword=editTextPassword.getText().toString();/fetchthePasswordformdatabaseforrespectiveusernameStringstoredPassword=IoginDataBaseAdapter.getSinlgeEntry(userName);/checkiftheStoredpasswordmatcheswithPasswordenteredbyuserif(password.equals(storedPassword)Toast.makeText(HomeActivity.thiszCongrats:Logi
10、nSuccessfullyToast丄ENGTH_LONG)show();dialog.dismiss();elseToast.makeText(HomeActivity.thiszUserNameorPassworddoesnotmatch1,Toast丄ENGTH_LONG)show(););dialog.show();(OverrideprotectedvoidonDestroy()super,onDestroy();loginDataBaseAdapter.close();/LoginDataBaseAdapter.javaimportandroid.content.ContentVa
11、lues;importandroid.content.Context;importandroid.database.Cursor;importandroid.database.SQLException;importandroid.database.sqlite.SQLiteDatabase;publicclassLoginDataBaseAdapterstaticfinalStringDATABASE_NAME=login.db;staticfinalintDATABASE_VERSION=1;publicstaticfinalintNAME_COLUMN=1;/TODO:Createpubl
12、icfieldforeachcolumninyourtable/SQLStatementtocreateanewdatabasestaticfinalStringDATABASEJ2REATE=createtable,+,LOGINH+n(11+,IDI,+Hintegerprimarykeyautoincrement,+HUSERNAMEtext,PASSWORDtext);H;/VariabletoholdthedatabaseinstancepublicSQLiteDatabasedb;/Contextoftheapplicationusingthedatabaseprivatefina
13、lContextcontext;/Databaseopen/upgradehelperprivateDataBaseHelperdbHelper;publicLoginDataBaseAdapter(Context_context)context=_context;dbHelper=newDataBaseHelper(context,DATABASESAME,null,DATABASE_VERSION);publicLoginDataBaseAdapteropen()throwsSQLExceptiondb=dbHelper.getWritableDatabase();returnthis;p
14、ublicvoidclose()db.close();publicSQLiteDatabasegetDatabaselnstance()returndb;publicvoidinsertEntry(StringuserNamezStringpassword)ContentValuesnewValues=newContentValues();/Assignvaluesforeachrow.newValues.putCUSERNAME,userName);newValues.putfPASSWORD蔦password);/Inserttherowintoyourtabledb.insert(,lL
15、OGINl,/null,newValues);/Toast.makeText(context,ReminderIsSuccessfullySaved,Toast.LENGTH_LONG).show();publicintdeleteEntry(StringUserName)/Stringid=String.vaIueOf(ID);Stringwhere=,USERNAME=?H;intnumberOFEntriesDeleted=db.delete(,LOGIN,/where,newStringUserName);/Toast,makeText(context,nNumberfoEntryDe
16、letedSuccessfully:+numberOFEntriesDeleted,Toast.LENGTH_LONG)show();returnnumberOFEntriesDeleted;publicStringgetSinlgeEntry(StringuserName)Cursorcursor=db.query(,LOGIN,/null,USERNAME=?,/newStringuserNameznull,null,null);if(cursor.getCount()l)/UserNameNotExistcursor.close();returnHNOTEXIST1;cursor.mov
17、eToFirst();Stringpassword=cursor.getString(cursor.getColumnlndex(,PASSWORD,);cursor.close();returnpassword;publicvoidupdateEntry(StringuserName,Stringpassword)ContentValuesupdatedValues=newContentValues();updatedValues-putCUSERNAME1,userName);updatedValues.put(PASSWORD舄password);Stringwhere=nUSERNAM
18、E=?“;db.update(,LOGIN,/updatedValues/where,newString口userName);/SignllPActivity.javaimportandroid.app.Activity;importandroid.os.Bundie;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.Toast;publicclassSignUPActivityextendsActivityEditTexteditText
19、llserNameditTextPasswordditTextConfirmPassword;ButtonbtnCreateAccount;LoginDataBaseAdapterloginDataBaseAdapter;OverrideprotectedvoidonCreate(BundlesavedlnstanceState)super,onCreate(savedlnstanceState);setContentView(R.layout.signup);/getInstanceofDatabaseAdapterloginDataBaseAdapter=newLoginDataBaseA
20、dapter(this);loginDataBaseAdapter=loginDataBaseAdapter.open();/GetRefferencesofViewseditTextUserName=(EditText)findViewByld(R.id.editTextUserName);editTextPassword=(EditText)findViewByld(R.id.editTextPassword);editTextConfirmPassword=(EditText)findViewByld(R.id.editTextConfirmPassword);btnCreateAccount=(Button)findViewByld(R.id.buttonCreateAccount);btnCreateAccount.setOnClickListener(newView.OnClickListener()publicvoidonClick(Viewv)StringuserName=editTextUserName.getText().toString();Stringpassword=editTextPassword.getText().toString
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年注册会计师考试《审计》真题及答案(完整版)
- 2025年注会考试试题及答案
- 2025年新版蜜雪冰城考试题目及答案
- 为中华之崛起而读书课件
- 承担责任主题班会
- 《渠系建筑物》课件
- 小数乘除法对比练习
- 四川省雅安市名山区前进乡初级中学2025-2026学年下期期末七年级英语试题(含答案)
- 2026-2030皮衣行业风险投资态势及投融资策略指引报告
- 哈尔滨市2025中国农业科学院哈尔滨兽医研究所动物流感基础与防控创新团队招聘笔试历年参考题库典型考点附带答案详解
- 新疆油气田钻井固体废物综合利用污染控制要求(DB 65-T 3997-2017)
- 中国融通资源开发集团有限公司物资接收、仓储人员专项招聘87人笔试模拟试题及答案详解
- 2026年共青团入团考试试题附标准答案
- 2026郑州市新初一三科分班摸底卷摸底卷
- 2026年渭南市大荔县数学三下期末统考模拟试题含答案
- (2024版)中国成人暴发性心肌炎诊断和治疗指南课件
- (2026年)痔疮的诊断和治疗健康宣教课件
- 老年人慢性病管理与护理
- (2026年)血气分析临床解读课件
- 分布式光伏开发建设导则
- 精神科物理治疗工作制度
评论
0/150
提交评论