There is a textview and a button in the XML file.
<linearlayout 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:orien tation= "vertical" 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 "> <!--an ID of TextView text width full parent container height adaptive background for red Primary text WJJ---<textview android:id=" @+id /textview "android:layout_width=" fill_parent "android:layout_height=" Wrap_content "Android:background = "#FF0000" android:text= "@string/wjj" > </TextView> <!--a button width with an ID of button adaptive height Adaptive primary text is but Ton--<button android:id= "@+id/button" android:layout_width= "Wrap_content" Android:layout_ Height= "Wrap_content"android:text=" button "/></linearlayout>
Java files
Package Com.wjj.day_01_genesis;import Android.app.activity;import Android.graphics.color;import android.os.Bundle; Import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public class Mainactivity extends Activity {private TextView Textview;private Button Button;int count = 0; @Overrideprotected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Set Layout File TextView = (TextView) Findviewbyid (R.id.textview); Find text Textview.setbackgroundcolor (Color.Blue); Sets the color of the text background Button = (Button) Findviewbyid (R.id.button); Find the button buttononclicklisnter Lisnter = new Buttononclicklisnter (); First, a listener button.setonclicklistener (lisnter); Set Listener for button}class Buttononclicklisnter implements Onclicklistener {//implement Onclicklistener interface @overridepublic void OnClick ( View view) {//This method is called when the button that binds this listener is pressed//TODO auto-generated method Stubcount++;textview.settext (cOunt + ""); Set the display of the text}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action Bar If it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
Snail-android Base button listener