码迷,mamicode.com
首页 > 其他好文 > 详细

点击事件

时间:2015-02-03 07:14:21      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:private   public   

1,点击事件几种方式:

  >>1,匿名内部类

public class MainActivity extends Activity {

 

          private Button btn;

          private TextView tv_show;

 

          @Override

          protected void 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

                              public void onClick(View v) {

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

                                         

                              }

                    });          

          }

}

>>2,类实现的方法

    private void clickTwo() {

                    btn.setOnClickListener(this);

                     

          }

技术分享

       @Override

       public void onClick(View v) {

                     

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

          }

>>3,xml 布局onClick

技术分享

 

 

/**

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

           * @param v

           */

          public void clickThree(View v){

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

 

          }

>>4,第四种方法

    public void 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;

          }

          }

 

本文出自 “xmy” 博客,请务必保留此出处http://88649164.blog.51cto.com/9890093/1610873

点击事件

标签:private   public   

原文地址:http://88649164.blog.51cto.com/9890093/1610873

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!