I added a button in layout and obtained its reference in the activity:
Button button1=(Button)findViewById(R.id.button1);
button1.setVisiblity(View.Visible);
Program crashes with this code. How do I set its visibility correctly?
Whats the error? it should be View.VISIBLE
(uppercase).
If you have a null pointer exception at that point, its probably because its not finding the view in your layout.
Steve,
Have you tried View.VISIBLE
make sure the VISIBLE
is in all caps.
the View.Visible should be in UpperCase , so try this :
button1.setVisibility(View.VISIBLE);
and if you aren't in the Activity and you want to change the Visibility , you should pass the Context of the Activity to that class in order to implement the method Acitivity.runOnUIThread(new Runnable());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With