how to add button click event in android studio

前端 未结 14 1359
面向向阳花
面向向阳花 2020-12-24 11:04

So I have done some research, and after defining you button as an object by the code

private Button buttonname;
buttonname = (Button) findViewById(R.id.butto         


        
14条回答
  •  萌比男神i
    2020-12-24 11:24

    //as I understand it, the "this" denotes the current view(focus) in the android program

    No, "this" will only work if your MainActivity referenced by this implements the View.OnClickListener, which is the parameter type for the setOnClickListener() method. It means that you should implement View.OnClickListener in MainActivity.

提交回复
热议问题