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: