No code required here to attach the listener
package app.test; import android.app.Activity; import android.os.Bundle; import android.view.View; public class Test extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //No code required here to attach the listener } public void onMyButtonClick(View v) { //Code to handle the click event } } //main.xml <?xml version="1.0" encoding="utf-8"?> <Button xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My Button" android:onClick="onMyButtonClick" />