Button has several Click response methods

php中世界最好的语言
Release: 2018-02-01 09:43:47
Original
2800 people have browsed it

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

event handling methods here and found that there are many implementation methods. I prefer the second one. What about you, which one is most commonly used? One?

Implementation one:

Button bt_Demo = (Button)findViewById(R.id.bt_Demo);
   bt_Demo.setOnClickListener(new OnClickListener()
   {
       @Override
       public void onClick(View v)
       {
           //响应Clicked事件
//......
       }
   });
Copy after login

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;
                }
       }
   }
Copy after login

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事件
//......
       }        
   }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!