Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

buttons: setVisibility vs setText

Tags:

android

Depending on the circumstance, the user has the choice between 2 buttons: BACK or DELETE To implement that, I have 2 choices:

  • Having 2 buttons, one visible and one "gone" using the setVisibility()
  • 1 button where the text is changed using setText()

Which is the better coding practice? Which is better for performance?
PS: My program actually has a lot more buttons with multiple choices.

like image 281
yes4me Avatar asked Jun 05 '26 08:06

yes4me


1 Answers

I'd suggest you to use setText() method because there is only one choice that the user needs to provide.

Using setVisibility() must to declare two Buttons in xml whereas your design does not need the two Buttons together. You only need one Button which switches according to the circumstance.

setText() might be better for performance because the design needs at least one choice displayed but never two choices at the same time.

However, if the two Buttons are radically differents and provide a different design (I mean more than just changing the background), use setVisibility() might be a better way rather than change width, height, margin, padding, etc. dynamically.

like image 108
Blo Avatar answered Jun 06 '26 22:06

Blo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!