how to add button click event in android studio

前端 未结 14 1319
面向向阳花
面向向阳花 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:17

    in Activity java class you would need a method first to find the view of the button as :

    btnSum =(Button)findViewById(R.id.button);
    

    after this set on click listener

    btnSum.setOnClickListener(new View.OnClickListener() {
    

    and override onClick method for your functionality .I have found a fully working example here : http://javainhouse.blogspot.in/2016/01/button-example-android-studio.html

提交回复
热议问题