how to add button click event in android studio

前端 未结 14 1322
面向向阳花
面向向阳花 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条回答
  •  粉色の甜心
    2020-12-24 11:26

    Your Activity must implement View.OnClickListener, like this:

    public class MainActivity extends 
    Activity implements View.OnClickListener{
    // YOUR CODE
    }
    

    And inside MainActivity override the method onClick(), like this:

    @override
    public void onClick (View view){
    //here YOUR Action response to Click Button 
    }
    

提交回复
热议问题