I have ListView. It contains 3 TextView not from activity_main.xml.
cursor = myDatabase.getJoinedInfo(etSearch.getText().toString().trim());
String[] columns = new String[] { "re_value", "g_value", "ke_value" };
int[] to = new int[] { R.id.tvHiragana, R.id.tvMeaning, R.id.tvKanji };
dataAdapter = new SimpleCursorAdapter(this, R.layout.wordonlist,
cursor, columns, to, 0);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
How to change font of TextViews inside ListView?
final Typeface mFont = Typeface.createFromAsset(getAssets(),
"fonts/himaji.otf");
LayoutInflater ltInflater = getLayoutInflater();
View view = ltInflater.inflate(R.layout.wordonlist, null, false);
tvHiragana=(TextView) view.findViewById(R.id.tvHiragana);
tvHiragana.setTypeface(mFont);
This code could not change TextView's font. What I am doing wrong?
You can style your
TextViewsin xml (e.g. the row layout), as outlined in the styles and themes article.If you need to programmatically change the font (e.g. only for some instances, or using parameters not known at compile-time), you could create an anonymous subclass (or a regular subclass) of
SimpleCursorAdapterwhich applies the changes in the adapter'sgetViewmethod. For that, see a slightly related answer to text color changing. Your code inflates the layout (thus creating a newViewinstance), and changes that single instance, not the instances added to your list.