Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
//declare and define the button
Button button = (Button) findViewById(R.id.button1);
//method 1: set the onclick eventlistener with java only
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
/////
//method 2:use also layout code (xml)
//xml:
//add the following :
android:onClick="functionName"
//to the view you want to add the eventlistener to
//java: add to the main class
public void functionName(View v) {
}
public void clickFunction (View view){}