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