android eclipse button OnClick event

前端 未结 6 1635
别跟我提以往
别跟我提以往 2020-12-18 08:03

I have 2 files: main_activity.xml and home.xml. I made a button in main_activity.xml

Here is the code snippet:



        
6条回答
  •  粉色の甜心
    2020-12-18 08:26

    You can use this code.

    Android: OnClickListener

    In our activity class we add the onclick method.

    In our activity class we add the onclick method.

        //On click event for button1
    public void button1OnClick(View v) {
        //Inform the user the button has been clicked
        Toast.makeText(this, "Button1 clicked.", Toast.LENGTH_SHORT).show();               
    }
    

    In the layout file we add a reference to the onclick handler in the activity. The app will automatically bind the onclick method to the view (in this case button1)

    
    
    
            

提交回复
热议问题