Attaching multiple listeners to views in android?

前端 未结 4 471
囚心锁ツ
囚心锁ツ 2020-12-16 10:23

Is it possible to attach multiple onClick listeners to buttons in android? Example:

btn1.setOnClickListener(listener1);
btn1.setOnCliclListener(listener2);
         


        
4条回答
  •  -上瘾入骨i
    2020-12-16 11:04

    public void onClick(View v) {
        if(v.getId() == R.id.button1) {
            // do this
        }else if(v.getId() == R.id.button2) {
            // do that
        }
    }
    

提交回复
热议问题