Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

font awesome in android list view not working

So I have created this custom array adapter:

        View row = convertView;
        ViewHolder holder;
        iconFont = Typeface.createFromAsset(activity.getAssets(), "fontawesome-webfont.ttf" );

        if (row == null) 
        {
            LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = layoutInflater.inflate(R.layout.event_type_list_row, null);
            holder = new ViewHolder();
            holder.icon = (TextView) row.findViewById(R.id.EventTypeListRow_icon_EditText);
            holder.name = (TextView) row.findViewById(R.id.EventTypeListRow_name_EditText);
            row.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) row.getTag();
        }
        final EventTypeDataObj eventType = data.get(position);
        if (eventType != null) 
        {
            //holder.icon.setText(eventType.getIconCode()); f02c;
            holder.icon.setText("");
            holder.icon.setTypeface(iconFont);
            holder.name.setText("");
            holder.name.setTypeface(iconFont);
        }

        return row;

I don't see the I cons, I see the code in the list view like here: enter image description here

Note: other fonts (which works on letters not icons). are working.

Is there amy reason it is not working?

like image 477
vlio20 Avatar asked Mar 21 '23 18:03

vlio20


1 Answers



is apparently an XML entity. I have no reason to believe android should treat the as such, and not as a plain string of characters. Which apparently it does, given your screenshot.

If you want to specify characters by giving their unicode value, the correct usage in java is \u, like so :

holder.name.setText("\uf001");

Edit

It is also possible, if your input is "&#f001;" and cannot be replaced by "\uf001" to use Html.fromHtml to decode the XML entities in the String:

holder.name.setText(Html.fromHtml("&#f001;"));
like image 157
njzk2 Avatar answered Mar 28 '23 14:03

njzk2