Home > Article > Web Front-end > Button has several Click response methods
This time I will bring you several Click response methods for Button. What are the precautions for using Button's Click response method? The following is a practical case, let's take a look.
Button is used a lot. I have sorted out its Implementation one:Button bt_Demo = (Button)findViewById(R.id.bt_Demo); bt_Demo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //响应Clicked事件 //...... } });Implementation two:
Button bt_Demo = (Button)findViewById(R.id.bt_Demo); bt_Demo.setOnClickListener(listener); private OnClickListener listener = new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub switch(arg0.getId()){ case R.id.bt_Demo: //响应Clicked事件 //...... break; default: break; } } }Implementation three:
Button bt_Demo = (Button)findViewById(R.id.bt_Demo); bt_Demo.setOnClickListener(new ButtonListener()); private class ButtonListener implements OnClickListener{ @Override public void onClick(View arg0) { //响应Clicked事件 //...... } }I believe you have mastered the method after reading these cases, For more exciting content, please pay attention to other related articles on the php Chinese website! Related reading:
How to make the html drop-down menu retain the selected value and not return to the default value after submission
How to html Example of adding attributes using style
#How to set focus on an html element
The above is the detailed content of Button has several Click response methods. For more information, please follow other related articles on the PHP Chinese website!