Android Design Login interface, retrieve password, register function _android

Source: Internet
Author: User

This example for you to share the Android login, retrieve password, registration function of the implementation code, for your reference, the specific contents are as follows

1. The design of the database

I added two tables to the database, a table to store user information, such as user name, password, mobile phone number, etc., can be added arbitrarily. Another table was used to store the account information of the last logged-on user, and I created a separate table to store for convenience, and I designed it to store only one piece of information, each time overwriting the previous record. In fact, I've tried to add an identity to the table where the user information is stored, which account is used to mark the last login, but in so doing, each change of identity needs to traverse the entire table, very troublesome, and I do not know what a more efficient method, after all, the level of limited, in this respect wading quite shallow, If the people who read this article know more effective and convenient method, please teach me, thank you.

There's nothing more to say about building statements, but the only thing worth mentioning is that, according to Google's official suggestion, we should put the table statement in a final class, of course, for our global variable is also a reason, so easy to manage, when you need to change a global information, you can directly find, Convenient for future maintenance. For example, my Ultimate class is the following->

Public final class Globemanager {public Globemanager () {} public static abstract class UserInfo {public static F
 inal String id = "id";
 public static final String USERNAME = "USERNAME";
 public static final String UserPassword = "password";
 public static final String tablename = "Usertable";
 public static final String DATABASENAME = "Userdatabse";

 public static final String PhoneNumber = "Phone";
 public static final String create_table = "CREATE TABLE" + tablename + ("+ ID +" Integer primary key AutoIncrement, "
 + USERNAME + "text," + PhoneNumber + "text," + UserPassword + "text";

 public static String Phonekey = "Phonekey";
 public static abstract class Recentusers {public static final String ID = "id";
 public static final String recentname = "Recentname";
 public static final String Recentpassword = "Recentpassword";
 public static final String Onlykey = "key";

 public static final String tablename = "recenttable"; public static final String create_table= "Create TABLE" + tablename + "(" +id + "Integer primary key AutoIncrement," +recentname + "text," +recentpass
 WORD + "text," +onlykey + "text";

 }
}

2. First look at the login interface

Overview design

Sign in button to set the Listener event, when the user clicks the button, first gets the information the user enters in the app ID and the Password input control, and then makes the following judgments about the information.

1. First use the IsEmpty () method in Textutils to determine if the input information is empty (Textutils.isempty () This method returns True if the parameter is null or "")

2). After the previous step has been properly executed, the following is a match of the user name and password that has been acquired to the information in the database, which is done by a specialized database management class, not done in the activity, and designed to be based on a single responsibility principle.

3. If you query the relevant username and password in the database, return the user class, encapsulate the information in it, and if not, return a null to facilitate the activity to judge.

3. Registration interface

About the App ID and Password input, pay attention to the corresponding legality judgment, followed by this mobile phone number, in real projects, this option should have the function of sending verification code, because the mobile phone number can be used for account password back, very important.

4. Password Retrieve

There is only one input mobile phone number control, input to the legality of judgment, for example, if the number of digits less than 11, then you can directly prompt, rather than go to the database to find it again, so the efficiency is very low. If you enter the phone number is legitimate, in the database to look for, if found, display the user's information->

Here, provides a password to modify the function, after all, if the user forgot the original password, may want to modify the password, in view of specific information can be directly modified is very humanized design.

5. About Alertdialog.builder

Sometimes, the style that Alertdialog.builder provides to us cannot satisfy us, for example, I want to set Positivebutton and Negativebutton to match our subject color, then we need to customize a style, as follows

 <style name= "Myalertdialog" parent= "Theme.AppCompat.Light.Dialog.Alert" >

 //For changing the color of the button
 <item Name= "Android:coloraccent" > @color/coloraccent</item>

 //used to change the color of the message word
 <item name= "Android: Textcolorprimary "> #000000 </item>
 </style>
 //To change the background color of dialog
 <item name=" Android: Background "> #4CAF50 </item>

Then just declare it in your code, and you can use a custom style.

Copy Code code as follows:
Final Alertdialog.builder Dialog = new Alertdialog.builder (this,r.style.myalertdialog);

SOURCE Download Address: Http://xiazai.jb51.net/201605/yuanma/AndroidAPP (jb51.net). rar

This is the entire content of this article, I hope to learn more about Android software programming help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.