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.


      Button buttonAdvert = (Button) findViewById(;
      CharSequence text = “Hello”;
      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);