Android button onclick override

后端 未结 3 1911
面向向阳花
面向向阳花 2020-12-10 03:24

I would like to create a CustomButton which has a predefined onClick. In fact, my object would do the same job than

CustomButton mB         


        
3条回答
  •  攒了一身酷
    2020-12-10 03:55

    Use that code:

    class CustomButton extends Button implements View.OnClickListener{
         CustomButton(Context c, AttributeSet attrs) {
             ...
             setOnClickListener(this);
             ...
         }
    
        @override
        public void onClick(View v){
            //add your code here
        }
    }
    

提交回复
热议问题