+ 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??

15th Mar 2018, 10:31 PM
yousef mohamed
yousef mohamed - avatar
3 odpowiedzi
+ 1
boolean clicked = false; button.setOnClickListener({ if(clicked){ textview.text=""; }else{ textview.text="hello" } clicked = !clicked; });
16th Mar 2018, 7:04 AM
Vladi Petrov
Vladi Petrov - avatar
+ 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.
15th Mar 2018, 10:53 PM
Vladi Petrov
Vladi Petrov - avatar
+ 1
can u write the code u mean in my code?
16th Mar 2018, 12:38 AM
yousef mohamed
yousef mohamed - avatar