Create TextView from template XML file
11,948
TextView txt = (TextView) View.inflate(this, R.layout.simple_txt, null);
Related videos on Youtube
Author by
yital9
Updated on June 15, 2022Comments
-
yital9 almost 2 years
I have a template of simple
TextView
in a filesimple_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 aTextView
like this? -
Dhunju_likes_to_Learn over 5 yearsfyi, generally passing null for last (root) param is not recommended but doing so is is essential here.