Snail-android Base button listener

Source: Internet
Author: User

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

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.