Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create TextView from template XML file

I have a template of simple TextView in a file simple_txt.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:textSize="18sp" >
</TextView>

In some code I need to create a TextView from this template, something like:

TextView txt = new TextView(this);
txt.setLayout(R.layout.simple_txt);//???

then do something with it (setText etc.). How can I create a TextView like this?

like image 256
yital9 Avatar asked Apr 12 '12 18:04

yital9


1 Answers

TextView txt = (TextView) View.inflate(this, R.layout.simple_txt, null);
like image 113
207 Avatar answered Oct 28 '22 03:10

207