Onclick To Textview Android
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
Solution 1:
Use the setter setText() in the button's on click listener.
myButton.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
myTextView.setText("new text");
}
});
Solution 2:
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(newView.OnClickListener(){
@OverridepublicvoidonClick(View v){
textView.setText("Hello World");
}
});
Post a Comment for "Onclick To Textview Android"