0

Is it possible to set the view of a view by taking data from a already created layout?

For example:

I have the layout file test_layout.XML

<TextView
    android:id="@+id/TextView1"
    android:text="TextView1"
    android:background="@color/wisteria"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>   

I now want to create a new view that is being created out of this TextView. If creating a new view out of a Drawable I would simply do:

imageView.setImageResource(R.drawable.shape1);

How do I create a new view, by including all the attributes in the TextView1? I simply want to create a new view out of a existing TextView. The TextView above acts as a "template". Should I do it by setViewById?

I hope I made myself clear, a little hard to describe.

matiash
  • 54,791
  • 16
  • 125
  • 154
klefar
  • 65
  • 8
  • I believe you want to [clone your view](http://stackoverflow.com/questions/4159211/how-do-i-clone-a-view)? – Uxonith May 30 '14 at 21:36

1 Answers1

0

Just use a LayoutInflater and inflate this resource again.

LayoutInflater inflater = LayoutInflater.from(context);
View v1 = inflater.inflate(R.layout.test_layout, null);
View v2 = inflater.inflate(R.layout.test_layout, null);
...
matiash
  • 54,791
  • 16
  • 125
  • 154