Android: how to handle button click

后端 未结 10 2215
刺人心
刺人心 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:14

    My sample, Tested in Android studio 2.1

    Define button in xml layout

    Java pulsation detect

    Button clickButton = (Button) findViewById(R.id.btn1);
    if (clickButton != null) {
        clickButton.setOnClickListener( new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                /***Do what you want with the click here***/
            }
        });
    }
    

提交回复
热议问题