I'm using a custom font throughout my application (which, incidentally, I've frustratingly found out that you have to apply programmatically by hand to EVERY control!), and I need to apply it to a listview. The problem is that I can't see where I'd set the textview used in the list's font to my custom font (as I never instantiate it - that's all taken care of by the adapter).
What I'd ideally like is to be able to use an adapter like this:
new ArrayAdapter(Context context, TextView textView, List<T> objects)
That way I could do: textView.setTypeface before populating my list. Does anyone know if there's a way to do something along these lines?
You can't do it that way because the text view resource you pass to the ArrayAdapter is inflated each time it is used.
You need to create your own adapter and provide your own view.
An example for your adapter could be
}
And then you could set that as such
Hopefully that should get you going.
First copy and paste the font files into assets/fonts folder. Then identify the textview.
You can Set base Adapter like follow Steps May be help you
Define your Base Adapter
by TypeFace Method you can set your font by add folder 'Fonts' in Assets then add your font in 'Fonts' Folder
then to set your adapter
If you don't want to create a new class you can override the getView method when creating your Adapter, this is an example of a simpleAdapter with title and subtitle:
where items is your ArrayList of Maps
hope that helps
holder.txt_name.setTypeface(Typeface.createFromAsset(activity.getAssets(), "font/nasimbold.ttf"));
In addition to the response of Moisés Olmedo - an alternative variant without creating a new class: