how to add button click event in android studio

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

    Start your OnClickListener, but when you get to the first set up parenthesis, type new, then View, and press enter. Should look like this when you're done:

    Button btn1 = (Button)findViewById(R.id.button1);
    
    btn1.setOnClickListener(new View.OnClickListener() {            
        @Override
        public void onClick(View v) {
    //your stuff here.
        }
    });
    

提交回复
热议问题