jramirez
jramirez

Reputation: 484

Define a view of a XML by code

I've a XML File that acts like a frame for the activities. I want to set the View I've added in the XML, but when I try it nothing is shown.

<View
    android:id="@+id/marco_container"
    style="@style/wrapFull"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

This is my Activity code:

setContentView(R.layout.marco);
LinearLayout li = (LinearLayout) findViewById(R.id.marco_container);
View view = View.inflate(getApplicationContext(), R.layout.prueba, null);
li.addView(view);

How can I add the View to the XML?

Upvotes: 0

Views: 54

Answers (1)

gosr
gosr

Reputation: 4708

You must use LayoutInflater. Something like:

setContentView(R.layout.marco);
LinearLayout li = (LinearLayout) findViewById(R.id.marco_container);
View view = getLayoutInflater().inflate(R.layout.prueba, li, false);
li.addView(view);

Upvotes: 2

Related Questions