How to get a view from a resource?

Use a LayoutInflater....The Entire Layout can be inflated, without dynamically creating it....

LayoutInflater li = LayoutInflater.from(context);
View theview = li.inflate(R.layout.whatever, null);

Approach seems to be little incorrect. You should put RelativeLayout to the xml as your TextView made, and inflate the whole xml. Afterwards, you will be free to add views to your layout. So, do this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+androi:id/relLayout>
  <TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+android:id/titreItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
  </TextView>
</RelativeLayout>

In your activity:

setContentView(R.layout.titreitem);
RelativeLayout layout = (RelativeLayout)findViewByid(R.id.relLayout);
layout.addView(...);

Tags:

Android