Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Button Visibility

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?

like image 279
Steve Avatar asked May 26 '11 14:05

Steve


3 Answers

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.

like image 95
jkhouw1 Avatar answered Nov 08 '22 14:11

jkhouw1


Steve,

Have you tried View.VISIBLE make sure the VISIBLE is in all caps.

like image 43
Will Tate Avatar answered Nov 08 '22 14:11

Will Tate


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());

like image 29
Houcine Avatar answered Nov 08 '22 13:11

Houcine