The following code shows how to associate  OnClickListener with the button. Later on, when the button is clicked and that handler is invoked, how to get the title to the button.

Code

      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);
       }