Snail bait-Android basic button listener

Source: Internet
Author: User

The XML file contains a textView and a button.

     
      
      
      
      
  
 

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); // sets the layout file textView = (TextView) findViewById (R. id. textView); // locate the text textView. setBackgroundColor (Color. BLUE); // set the color of the text background. button = (Button) findViewById (R. id. button); // find the button buttonOnClickLisnter lisnter = new buttonOnClickLisnter (); // a listener button is first recognized. 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 bound to this listener is pressed. // TODO Auto-generated method stubcount ++; textView. setText (count + ""); // set text display }}@ 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 ;}}


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.