DoubleP90
DoubleP90

Reputation: 1249

Include layout and exclude another one

In my project i have 3 xml files.

My main layout

and 2 layouts which i want to include in my main layout

*big_buttons.xml* >contains big size buttons *small_buttons.xml* >contains the same buttons as above (same id's aswell) but they are smaller

By default i want the *big_buttons.xml* included, but id like to be able to "exclude" the *big_buttons.xml* and include the *small_buttons.xml* programmaticly after an onClickListener

Is it possible to do something like this?

Upvotes: 0

Views: 495

Answers (2)

WOUNDEDStevenJones
WOUNDEDStevenJones

Reputation: 5315

By default you can use setContentView(R.layout.big_buttons);, and then in your onClickListener you could do setContentView(R.layout.small_buttons);

If it's specific buttons you want excluded rather than the entire XML, I think you need to combine the 2 XML files and by default give the "big buttons" the attribute android:visibility="visible" and the "small buttons" android:visibility="gone".

Then programmatically you can do

    Button bigButton = (Button) findViewById(R.id.big_button);
    Button smallButton = (Button) findViewById(R.id.small_button);

    bigButton.setVisibility("View.GONE");
    smallButton.setVisibility("View.VISIBLE");

You'll want to use GONE rather than INVISIBLE because GONE excludes layout features like height and width, where INVISIBLE just doesn't display the button, but keeps space for it.

Upvotes: 1

mportuesisf
mportuesisf

Reputation: 5617

Check out View.setVisibility. You can use this on a layout manager, so that you can make entire groups of controls visible or invisible from Java code.

Upvotes: 0

Related Questions