If you just want to hide the text and not the b.setVisibility(View.GONE) button b.setVisibility(View.GONE) , this will not work.
It will hide the button itself, and also the button will not occupy any place in your layout, since you are using View.GONE.
Using b.setText("") should help you set only the empty text on the button.
You may need to call invalidate() to update the interface.
Nargis
source share