Thursday, 22 August 2013

How to get reference for TextView which is not in activity_main.xml?

How to get reference for TextView which is not in activity_main.xml?

wordonlist.xml:
<TextView
android:id="@+id/tvHiragana"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Hiragana"
android:textColor="@color/blackColor"
android:textColorHint="@color/blackColor"
android:textSize="18sp" />
MainActivity:
setContentView(R.layout.activity_main);
tvHiragana = (TextView) findViewById(R.id.tvHiragana);
Typeface tf =
Typeface.createFromAsset(getAssets(),"fonts/JapaneseLetter.ttf");
tvHiragana.setTypeface(tf,Typeface.BOLD);
Result:
NullPointerException in the line tvHiragana.setTypeface(tf,Typeface.BOLD);
I think it is because of TextView which is not in activity_main.xml. How
to get reference for TextView which is in wordonlist.xml?

No comments:

Post a Comment