Code-only Android login Layout

Source: Internet
Author: User
The following code implements login without any xml configuration. It seems that there is no clear example of using xml configuration.
/**
*
*/
Package com. Birds. Android. login;
Import Android. App. activity;
Import Android. App. alertdialog;
Import Android. App. alertdialog. Builder;
Import Android. content. dialoginterface;
Import Android. OS. Bundle;
Import Android. Text. inputfilter;
Import Android. Text. method. passwordtransformationmethod;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;
Import Android. widget. edittext;
Import Android. widget. tablelayout;
Import Android. widget. tablerow;
Import Android. widget. textview;
/**
* @ Author birds
* @ Date 2008-11-22
* @ File $
*/
Public class logincodeui extends activity implements onclicklistener {
Private Static final int button_id_ OK = 5000000;
Private Static final int button_id_cancel = 6000000;
Private Static final int text_id_one = 111111;
Private Static final int text_passwds = 222222;
/*
* (Non-javadoc)
*
* @ See Android. App. Activity # oncreate (Android. OS. Bundle)
*/
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Tablelayout = new tablelayout (this );
Setcontentview (tablelayout );
Tablerow row1 = new tablerow (this );
Tablelayout. addview (row1 );
Textview view1 = new textview (this );
View1.settext ("Account name :");
View1.setwidth (100 );
Edittext text1 = new edittext (this );
Text1.setwidth (150 );
Text1.setsingleline ();
Text1.setfilters (New inputfilter [] {New inputfilter. lengthfilter (15 )});
Text1.setid (text_id_one );
Row1.addview (view1 );
Row1.addview (text1 );
Tablerow row2 = new tablerow (this );
Tablelayout. addview (row2 );
Textview view2 = new textview (this );
View2.setwidth (100 );
View2.settext ("account password :");
Edittext text2 = new edittext (this );
Text2.setsingleline ();
Text2.setwidth (150 );
// Set to password Mode
Text2.settransformationmethod (New passwordtransformationmethod ());
// Set the maximum length to 15
Text2.setfilters (New inputfilter [] {New inputfilter. lengthfilter (15 )});
Text2.setid (text_passwd );
Row2.addview (view2 );
Row2.addview (text2 );
Tablerow row3 = new tablerow (this );
Tablelayout. addview (row3 );
Button b1 = new button (this );
B1.settext ("OK ");
B1.setid (button_id_ OK );
B1.setonclicklistener (this );
Button b2 = new button (this );
B2.settext ("cancel ");
B2.setid (button_id_cancel );
B2.setonclicklistener (this );
Row3.addview (B1 );
Row3.addview (B2 );
}
@ Override
Public void onclick (view v ){
Edittext T1 = (edittext) findviewbyid (text_id_one );
Edittext t2 = (edittext) findviewbyid (text_passwd );
If (V. GETID () = button_id_ OK ){
Builder alertdialog = new alertdialog. Builder (this );
Alertdialog. setpositivebutton ("OK ",
New dialoginterface. onclicklistener (){
Public void onclick (dialoginterface V, int BTN ){
V. Cancel ();
}
});
Alertdialog. settitle ("input information:" + t1.gettext () + "Password :"
+ T2.gettext ());
Alertdialog. Show ();
} Else if (V. GETID () = button_id_cancel ){
T1.settext ("");
T2.settext ("");
}
}
}
Xml configuration layout has obvious flexibility. The Code mainly implements logic functions and has some MVC ideas.
XML is the view configuration, the logic code is written into the class, and the Android event listening is the controller.
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.