Android: how to handle button click

后端 未结 10 2224
刺人心
刺人心 2020-11-27 11:08

Having a solid experience in non-Java and non-Android area, I\'m learning Android.

I have a lot of confusion with different areas, one of them is how to handle butt

10条回答
  •  无人及你
    2020-11-27 11:20

    To make things easier asp Question 2 stated, you can make use of lambda method like this to save variable memory and to avoid navigating up and down in your view class

    //method 1
    findViewById(R.id.buttonSend).setOnClickListener(v -> {
              // handle click
    });
    

    but if you wish to apply click event to your button at once in a method.

    you can make use of Question 3 by @D. Tran answer. But do not forget to implement your view class with View.OnClickListener.

    In other to use Question #3 properly

提交回复
热议问题