/this is the creation of an OnClickListener/
View.OnClickListener myOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//do the things u need to do when u click the view
}
};
/this is the part when u set the on click listener/
myButton.setOnClickListener(myOnClickListener);
Another way to do that is to implement the on click listener
public class MyActivity extends Activity implements OnClickListener{
//the code of your activity
@Override
public void onCreate(...){
myButton.setOnClickListener(this);
}
//some other methods
@Override
public void onClick(View v) {
if(v.getId == R.id.theIdOfTheViewInXML)
//do the things u need to do when u click the view
}
}