zoukankan      html  css  js  c++  java
  • android点击事件写法

     
    1、btn = (Button)findViewById(R.id.btn1);
            btn.setOnClickListener(new OnClickListener() {
                
                public void onClick(View v) {
                    Toast.makeText(getBaseContext(), "Button click", Toast.LENGTH_SHORT).show();
                }
            });
    2、 btn.setOnClickListener(clickListener);
         private OnClickListener clickListener = new OnClickListener() {
           
            public void onClick(View v) {
                switch (v.getId()) {
                case R.id.btn1:
                    Toast.makeText(getBaseContext(), "Button click", Toast.LENGTH_SHORT).show();
                    break;

                default:
                    break;
                }
            }
        };

    3、xml中调用onClick方法:

       <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onClick"
            android:text="btn1" />
    public void onClick(View v)
        {
            switch (v.getId()) {
            case R.id.btn1:
                Toast.makeText(getBaseContext(), "Button click", Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
            }
           
        }

  • 相关阅读:
    基础问题汇总
    c primer plus 习题答案(5)
    c primer plus 习题答案(4)
    c primer plus 习题答案(3)
    c primer plus 习题答案(2)
    c primer plus 习题答案(1)
    渲染引擎之材质系统
    渲染引擎之坐标变换
    渲染引擎之底层视角
    渲染引擎之渲染管线
  • 原文地址:https://www.cnblogs.com/crane13/p/3150165.html
Copyright © 2011-2022 走看看