Click Event Processing Method and create a registration form (1). Click Event implementation and click form

Source: Internet
Author: User

Click Event Processing Method and create a registration form (1). Click Event implementation and click form

Development steps:

  • Declare an interactive component object
  • Instantiate the findViewById (ID Resource Name) of the interaction Component Object)
  • You can customize an event listening class to monitor the actions of all interactive components on the interface. This class must implement an interface View. OnclickListener to listen to event components.
  • Button bound to custom listener

Code:

1 public class LoginActivity extends AppCompatActivity {2 3 private Button btnLogin; // declare the Interaction class component object 4 5 @ Override 6 protected void onCreate (Bundle savedInstanceState) {7 super. onCreate (savedInstanceState); 8 setContentView (R. layout. activity_login); 9 10 this. btnLogin = (Button) this. findViewById (R. id. btnLogin); // instantiate the findViewById (ID Resource Name) 11 12 this. btnLogin. setOnClickListener (new ViewOcl (); // The button is bound to the custom listener 13 14} 15 private class ViewOcl implements View. onClickListener {// custom an event listening class to listen on the actions of all interactive components on the interface. This class must implement an interface View. onclickListener: listens to event components 16 @ Override17 public void onClick (View v) {18 switch (v. getId () {19 case R. id. btnLogin: 20 Toast. makeText (getApplicationContext (), "you have clicked the logon button", Toast. LENGTH_LONG ). show (); 21 break; 22 case R. id. btnRegister: 23 break; 24 default: break; 25} 26} 27} 28}LoginActivity. java

Run:

 

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.