Steve
Steve

Reputation: 130

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?

Upvotes: 5

Views: 32056

Answers (4)

Marius Van Wyk
Marius Van Wyk

Reputation: 71

If you are Using C# you can use

 button1.Visibility = ViewStates.Visible;

I had the same problem originally.

Upvotes: 0

jkhouw1
jkhouw1

Reputation: 7350

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.

Upvotes: 15

Houcine
Houcine

Reputation: 24181

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

Upvotes: 4

Will Tate
Will Tate

Reputation: 33509

Steve,

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

Upvotes: 3

Related Questions