我有这个自定义阵列适配器:
public class CustomAdapter extends ArrayAdapter<DataObj>
{
int layoutResourceId;
List<DataObj> data;
Activity activity;
Typeface iconFont;
public CustomAdapter(Activity activity, int layoutResourceId, List<DataObj> data)
{
super(activity, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.activity = activity;
this.data = data;
iconFont = Typeface.createFromAsset(activity.getAssets(), "icons.ttf" );
}
public static class ViewHolder
{
public TextView icon;
public TextView name;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
ViewHolder holder;
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.layout_icon_EditText);
holder.name = (TextView) row.findViewById(R.id.layout_name_EditText);
row.setTag(holder);
}
else
{
holder = (ViewHolder) row.getTag();
}
final DataObj obj = data.get(position);
if (eventType != null)
{
holder.icon.setText(obj.getIconCode());
holder.icon.setTypeface(iconFont);
holder.name.setText(obj.getName());
}
return row;
}
}
我看到的不是图标,而是代码(我使用 IcoMoon 作为我的图标字体)。可以看到我的应用程序中静态创建的其他图标,但在这里我看到了这个: 我的代码有什么问题吗?
这是静态时它的工作原理(它不是图像,而是 IcoMoon 的字体):
注意:我尝试使用其他字体(不是图标字体)并且它有效,似乎只有图标字体不起作用。
最佳答案
为什么你不尝试:
TextView text = new TextView();
String str = "some text";
SpannableStringBuilder sb = new SpannableStringBuilder(str);
sb.setSpan(iconFont, 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextSize(18);
text.setText(sb);
关于java - 自定义 ArrayAdapter 中未出现字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21439707/