Reputation: 1511
When I get a layout from xml and use setVisibility(INVISIBLE)
I cannot write that in the onCreate()
method but inside action Listener like onclick
you can write the code setVisibility
and hide the layout, how come I cannot write and set visibility
of that layout in onCreate
?
Upvotes: 1
Views: 1582
Reputation: 139
You can set Layout visibility in android to (visible/invisible/gone) by the XML code like: android:visiblity = "invisible"
Or you can use the Attributes list, example:screenshot of "Option" in Attributes list to set the visibility of a layout.
Upvotes: -1
Reputation: 4691
After setContentView()
in onCreate()
, find the View
on which you want to call setVisiblity()
.
setContentView(R.layout.activity_main);
Output = (TextView) findViewById(R.id.Output);
Output.setVisibility(View.VISIBLE);
Upvotes: 1
Reputation: 2558
You don't have View's view object inside the onCreate()
obviously you should specify it like setVisibility(View.INVISIBLE);
Where as in onClick(View v)
it already passes the View's view object so no need to specify there. simply you can use that.
I hope it would help you
Upvotes: 5