Piolo Opaw
Piolo Opaw

Reputation: 1511

I cannot setVisibility and specific layout from onCreate() in android but in onClick you can do it?

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

Answers (4)

Basil Rawa
Basil Rawa

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

Gaurav Gupta
Gaurav Gupta

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

Akbarsha
Akbarsha

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

Amresh
Amresh

Reputation: 2108

Use setVisibility(View.INVISIBLE) .

Upvotes: 2

Related Questions