How to set text in the Text View by using button on click both are present in the same Activity?
I have already used the Text View on using the same Text View the Stopped working
How to set text in the Text View by using button on click both are present in the same Activity?
I have already used the Text View on using the same Text View the Stopped working
Use the setter setText() in the button's on click listener.
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myTextView.setText("new text");
}
});
Here is the code that can help you with this.
Button button;
TextView textView;
button = (Button) findViewById(R.id.main_button);
textView = (TextView) findViewById(R.id.main_text);
// set the text view inside the button's OnClickListener() method
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
textView.setText("Hello World");
}
});