点击事件

1,点击事件几种方式:

成都创新互联长期为1000多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为广宗企业提供专业的成都网站设计、网站建设、外贸网站建设广宗网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。

  >>1,匿名内部类

publicclass MainActivityextends Activity {

 

          private Buttonbtn;

          private TextViewtv_show;

 

          @Override

          protectedvoid onCreate(Bundle savedInstanceState) {

                    super.onCreate(savedInstanceState);

                    setContentView(R.layout.activity_main);

                    btn = (Button) findViewById(R.id.btn);

                    tv_show = (TextView) findViewById(R.id.tv_show);

                    //第一种匿名内部类

                    btn.setOnClickListener(new OnClickListener() {

                               

                              @Override

                              publicvoid onClick(View v) {

                                        tv_show.setText("好啦,马上到!!");

                                         

                              }

                    });          

          }

}

>>2,类实现的方法

    privatevoid clickTwo() {

                    btn.setOnClickListener(this);

                     

          }

点击事件

       @Override

       publicvoid onClick(View v) {

                     

                    tv_show.setText("好啦,马上到!!");

          }

>>3,xml 布局onClick

点击事件

 

 

/**

           * 第三种方法:第一个修饰用public 第二个方法里面 View

           *@param v

           */

          publicvoid clickThree(View v){

                    tv_show.setText("各位同学请注意:今天下午苍老师来华育六班视察!!");

 

          }

>>4,第四种方法

    publicvoid onClick(View v) {

                     

           switch (v.getId()) {

          case R.id.btn:

                    tv_show.setText("好啦");

                    break;

          case R.id.btn2:][

                    tv_show.setText("好啦,马上到!!");

                    break;

          case R.id.btn3:

                    tv_show.setText("好啦,马上到!!今晚华育小树林见!!");

                    break;

 

          default:

                    break;

          }

          }

 


本文标题:点击事件
标题URL:http://abwzjs.com/article/gcpdjd.html