The following code shows how to associated the OnClickListener with the button and later on when its clicked and that handler is invoked how to get the title to the button.

Button buttonAdvert = (Button) findViewById(R.id.button_advert);
       
        CharSequence text = "Hello";
        buttonAdvert.setText(text);

        buttonAdvert.setOnClickListener(new View.OnClickListener()

{
            public void onClick(View view) {
                Log.d("in : Button Advert onClick(..)");
               
              // cast the view instance into  button
            Button b = (Button)v;
           String buttonText = b.getText().toString();

           Log.d("Button title " + buttonText);

}