-1

Can anyone tell me how can i change the random button name when click on that button.

adig
  • 115
  • 1
  • 3
  • 9

3 Answers3

1
button.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v)
   {
        button2.setText("New Text");
   }

);
Sadeshkumar Periyasamy
  • 4,848
  • 1
  • 26
  • 31
1

Do you want the name to be random or you want a particular name when you click that button?

If you want a random name, then use the following code:

Button yourButton = (Button) findViewById(R.id.buttonid);
yourButton.setOnClickListener(new OnClicklistener(){
@Override
public void OnClick(View v)
{
   ((Button)v).setText(q);

}
});

Here q is nothing but the string which you will be obtained by following answer Show random string

And for particular name, you can follow the other answers.

Community
  • 1
  • 1
Parth Dani
  • 535
  • 4
  • 19
0

Can't really help much with that little information, but here is a quite generic way to achieve what you seem to want:

Button yourButton = (Button) findViewById(R.id.buttonid);
yourButton.setOnClickListener( new OnClickListener(){
    @Override
    public void onClick(View v){
        ((Button) v).setText("new text");
    }
});
Jave
  • 31,598
  • 14
  • 77
  • 90
  • thanks for the answer, but what I mean is if the button on click it will change the button text itself – adig Mar 07 '12 at 13:49
  • @adig I'm not quite sure I get what you mean. This code does change the text of the button itself. – Jave Mar 07 '12 at 13:53
  • yes, it did change. but I mean the show more than one text at random if the button is clicked – adig Mar 07 '12 at 14:37