My Android learning footstep-----------Button and listener Setonclicklistener

Source: Internet
Author: User

Basic learning, set a button and listen for real time display

First XML layout, drag a button to the appropriate location in the Activity_main.xml in layout

Then make the changes in the XML file

<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" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/activity_ Vertical_margin "tools:context=". Mainactivity "> <textview android:id=" @+id/show "android:layout_width=" Wrap_content "Android : layout_height= "wrap_content" android:text= ""/> <button android:id= "@+id/ok" android:layout        _width= "Wrap_content" android:layout_height= "wrap_content" android:layout_alignleft= "@+id/textView1" android:layout_below= "@+id/textview1" android:layout_margintop= "25DP" android:text= "click Me"/></relativel Ayout> 

The main modification ID and text (View and button), wrap_content indicates that the component length or height is determined by the text of the package.

Modify inside the Mainactivity.java, add buttons and listeners

Package Org.crazyit.helloworld;import Android.os.bundle;import Android.app.activity;import android.view.DragEvent; Import Android.view.menu;import Android.view.view;import Android.view.view.ondraglistener;import Android.widget.button;import Android.widget.textview;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); Button bn = (Button) Findviewbyid (R.id.ok), Bn.setonclicklistener (new View.onclicklistener () {public void OnClick (View V {Final TextView show = (TextView) Findviewbyid (r.id.show); Show.settext ("Hello android~" + New Java.util.Date ());}});}}

Complete.

My Android Learning footstep-----------Button and listener Setonclicklistener

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.