Font awesome in android list view not working

So, I 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 I am cons, I see the code as a list, like here: enter image description here

Note: other fonts (which work with letters, not icons). work.

Is there a reason it doesn't work?

+4
source share
2 answers


seems to be an XML object. I have no reason to believe that the android should be considered as such, and not as an ordinary string of characters. Which apparently does this, given your screenshot.

, , java \u, :

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

, "&#f001;" "\uf001", Html.fromHtml XML String:

holder.name.setText(Html.fromHtml("&#f001;"));
+7

- strings.xml , getString(R.string.whatever). Android Unicode.

0

Source: https://habr.com/ru/post/1524358/


All Articles