Android Combat Simple Tutorial-22nd gun (based on Baas user registration function)

Source: Internet
Author: User
Tags gettext

The user registration function is implemented based on Baas.

We use the API provided by Bmob for real-life development, first download the SDK on the Bmob website, and then copy the jar package into the project.

To create an app, get the app key:


1.main.xml:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"     xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent ">    <TableLayout        android:id=" @+id/tl "      & nbsp Android:layout_width= "Match_parent"         android:layout_height= "Wrap_content" >        <TableRow>            <TextView        &NB Sp       android:id= @+id/tv_name                 Android:layout_widt H= "Wrap_content"                 android:layout_height= "Wrap_content"                 android:text= "user name:"/>            <ed ittext              &NBSP Android:id= "@+id/et_username"                 android:layout_width= "Wrap_ Content "                android:layout_height=" wrap_content "                android:minwidth= "50DP"                 Android: Text= ""/>        </TableRow>        <TableRow>    &NBSP ;       <TextView                android:id= "@+id/tv_password" &nb Sp               android:layout_width= "wrap_content"           &NB Sp     android:layout_height= "wrap_content"                 android:text= " Password:/>            <EditText                an Droid:id= "@+id/et_password"                android:layout_width=" wrap_content "        &N Bsp       android:layout_height= wrap_content                 Android: Minwidth= "50DP"                 android:text= ""/>        &L t;/tablerow>    </TableLayout>    <Button        android:id= "@+id/ Register         android:layout_width= "match_parent"         Android:layout_ height= "Wrap_content"         android:layout_below= "@+id/tl"         Android:o nclick= "Submit"         android:text= "register"/></relativelayout>


2.mainactivity.java:

Package Com.example.logintest;import Org.w3c.dom.userdatahandler;import Cn.bmob.v3.bmob;import Cn.bmob.v3.listener.savelistener;import Android.os.bundle;import Android.app.activity;import Android.view.Menu; Import Android.view.view;import Android.widget.edittext;import Android.widget.toast;public class MainActivity Extends Activity {private EditText musername,mpassword; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Bmob.initialize (This, "8f3ffb2658d8a3366a70a0b0ca0b71b2");//Initialize, the second item to create an app for the official website key.musername= (EditText) Findviewbyid (r.id.et_username); mpassword= (EditText) Findviewbyid (R.id.et_password);} public void Submit (view view) {//Click event String Username=musername.gettext (). toString (); String Password=mpassword.gettext (). toString (); if (Username.equals ("") | | Password.equals ("")) {Toast.maketext (")" Username or password cannot be empty! ", 3). Show ();} Else{user user=new User (); User.setusername (username); User.setuserpassword (password); user. Save (Mainactivity.this,new Savelistener () {@Overridepublic void onsuccess () {Toast.maketext (Mainactivity.this, " Registration Successful! ", 3). Show ();} @Overridepublic void onfailure (int arg0, String arg1) {toast.maketext (Mainactivity.this, "Registration failed! ", 3). Show ();}});}}}

3. Configure permissions:

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Com.example.logintest "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/> <uses-permission android:name=" android.pe Rmission. INTERNET "/> <uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE "/> <uses-permission an Droid:name= "Android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name= " Android.permission.READ_PHONE_STATE "/> <uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/> <uses-permission android:name=" Android.permission.READ_LOGS "/> <application android: Allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:them E= "@style/apptheme" > <activity android:Name= "com.example.logintest.MainActivity" android:label= "@string/app_name" > <intent-filter&gt                ; <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. LAUNCHER "/> </intent-filter> </activity> </application></manifest>
4.javabean.java:

Package Com.example.logintest;import Cn.bmob.v3.bmobobject;public Class User extends Bmobobject {private String Userpassword;public String Getuserpassword () {return userpassword;} public void SetUserPassword (String userpassword) {This.userpassword = UserPassword;} Public String GetUserName () {return userName;} public void Setusername (String userName) {this.username = UserName;} Private String UserName;}

Running an instance:

We look at the official website of the data browsing, you can find a user form, there are two registration data, registration success!

Like a friend can pay attention to me! Thanks a lot

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Combat Simple Tutorial-22nd gun (based on Baas user registration function)

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.