listview - Custom Font in ExpandableListView Android

I wanted to make custom font for one of my textview but i'm still getting

cannot resolve method getAssets()

Here is a part of code:

public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    final String childText = (String)getChild(groupPosition, childPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater)this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, parent, false);

    TextView txtListChild   = (TextView)convertView.findViewById(;
    txtListChild.setTypeface(null, Typeface.BOLD);

    TextView kategoria  = (TextView)convertView.findViewById(;

    custom_font = Typeface.createFromAsset(getAssets(), "fonts/capture.ttf");

I want to make it with this code:

custom_font = Typeface.createFromAsset(getAssets(), "fonts/capture.ttf");

3 Answers

  1. Laurent- Reply


    update your code to this it will work:

    custom_font = Typeface.createFromAsset(mContext.getAssets(), "fonts/capture.ttf");

    You can't access your assets without context of your view. So Context is mandatory

    instead of setting the fonts inside getView method you can define fonts in your custom textview class, by using this it will take less memory and your app performance will be better.

  2. Lawrence- Reply


    You can call getAssets with a context. Use this:

    custom_font = Typeface.createFromAsset(this._context.getAssets(), "fonts/capture.ttf");

    Good luck.

  3. Leander- Reply


    As you want to use it into Adapter from your code

    Do the below changes

    Use Context

    Make Sure in your asset folder under fonts there is file of capture.ttf

    check Path for file capture.ttf

     Context context = null;
                Typeface custom_font = Typeface.createFromAsset(context.getAssets(), "fonts/capture.ttf");

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>