Android study Note 1: helloworld

Source: Internet
Author: User

Learning a new language, of course, begins with helloworld. Now let's start our journey to helloworld for Android. If you don't talk much about it, simply go to the code. There are not many changes to this program, only the main activity and Main. XML files.

Package Snoopy. android. first; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. textview; public class helloworldactivity extends activity {// call back this method when this activity is created for the first time @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // sets the main. set page layout defined by the XML file Contentview (R. layout. main); // obtain the ID in the UI as R. id. OK button bn = (button) findviewbyid (R. id. OK); // bind a listener bn for the click event to the button. setonclicklistener (New onclicklistener () {public void onclick (view v) {// obtain the ID in the UI as R. id. show text box final textview show = (textview) findviewbyid (R. id. show); // change the text content of the text box show. settext ("Hello Android ~ "+ New java. util. Date ());}});}}

This is the corresponding activity file.

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >
<! -- Text box -->
<Textview Android: Id = "@ + ID/Show" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = ""/> <! -- Set the text of the button to "Click me" --> <button Android: text = "Click me" Android: Id = "@ + ID/OK" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> </linearlayout>

 

Main. xml file

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.