Android Study Notes 2: dynamic generation Interface

Source: Internet
Author: User

In Android, the interface can be designed in advance in the. xml file, or dynamically generated in Java code.

 
Package Snoopy. android; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. view. viewgroup; import android. widget. button; import android. widget. linearlayout; import android. widget. textview; public class codeview extends activity {// this method is called back when this activity is created for the first time @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // create a linear layout manager linearlayout layout = new linearlayout (this); // set the activity to display layoutsuper. setcontentview (layout); layout. setorientation (linearlayout. vertical); // create a textviewfinal textview show = new textview (this); // create a button bn = new button (this); bn. settext (R. string. OK); // specifies the layout of length and height. wrap_content indicates the content to be adapted to bn. setlayoutparams (New viewgroup. layoutparams (viewgroup. layoutparams. wrap_content, viewgroup. layoutparams. wrap_content); // Add textviewlayout to the layout container. addview (show); // Add the button layout to the layout container. addview (BN); // bind an event listener bn to the button. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {Show. settext ("Hello, Android," + new Java. util. date ());}});}}

 

Program

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.