0

I want to set a custom typeface for a Textview in ListView Adapter ViewHolder. My typeface font file is in assets folder, so I will need a context reference in my adapter class to access the assets path and also I don't want to pass a context reference to my adapter class constructor. Should I use context reference through Dagger2 DI or should I make a separate DI Component to get reference of my font Typeface class.

Thanks in advance.

sumit soni
  • 70
  • 1
  • 7

1 Answers1

2

In ViewHolder you have access to View and all Views have access to context by getContext method.

hadilq
  • 1,023
  • 11
  • 25
  • thanx. its working.Also should I make a separate DI component to get access to my Typeface file reference? or continue to access it via getContext?? – sumit soni Jul 17 '16 at 14:47
  • I prefer to have a singleton manager to hold and change Typefaces. Then I inject this manager by my app component(my main component) instead of all the time reading needed Typefaces from resources. – hadilq Jul 18 '16 at 05:15