+ 1
How to hide text with button click in android studio
now i linked textview with button with this code button.setOnClickListener({ textview.text="hello" }) now wheb the button clicked it shows hello how to make when the button clicked again to hide the text??
3 Réponses
+ 1
boolean clicked = false;
button.setOnClickListener({
if(clicked){
textview.text="";
}else{
textview.text="hello"
}
clicked = !clicked;
});
+ 2
Make one variable for example clicked which is initialize with false and then in click listener check. If clicked remove text, if clicked is false add text.
+ 1
can u write the code u mean in my code?