The first Android app--Starting with HelloWorld

Source: Internet
Author: User

Java files

Package Org.crazyit.helloworld;

Import Android.os.Bundle;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.view.View;
Import Android.widget.TextView;

public class Helloworldactivity extends Activity
{
@Override
public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
interface layouts defined using the Hello_world.xml file
Setcontentview (R.layout.hello_world);
}

@Override
public boolean Oncreateoptionsmenu (Menu menu)
{
Getmenuinflater (). Inflate (R.menu.hello_world, menu);
return true;
}
public void ClickHandler (View source)
{
Gets the text box with ID r.id.show in the UI interface
TextView TV = (TextView) Findviewbyid (r.id.show);
Change the text contents of a text box
Tv.settext ("Hello android-" + New Java.util.Date ());
}
}

XML file

<relativelayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:tools= "Http://schemas.android.com/tools" >
<textview
Android:id= "@+id/show"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_centerinparent= "true"
Android:layout_alignparenttop= "true"
Android:textsize= "20SP"
android:text= "@string/hello_world"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@id/show"
android:text= "Click Me"
android:onclick= "ClickHandler"
/>
</RelativeLayout>

The first Android app--Starting with HelloWorld

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.