Changing TextView text on button click (Android)

  1. First you give onclick event for Button like (buttonClick).
  2. In java file just write below code.

    public void buttonClick(View v)
    {
    TextView tv = (TextView)findViewById(R.id.textView1);
    tv.setText("Welcome to android");
    }
    

Hope this will help you.


Maybe you need to initialize the button. And if it doesn't work, just do it in java code :

Button btn = (Button) findViewById(YourId);
btn.setonClickListener(listener);

public onClickListener listener = new View.OnclickListener{
      onclick(View v){
      // do your thing
      }
}

Something like that, i don't remember without eclipse to correct me.

Tags:

Android