Reputation: 130
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
Reputation: 71
If you are Using C# you can use
button1.Visibility = ViewStates.Visible;
I had the same problem originally.
Upvotes: 0
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
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