I have a ListView with a hundred items that scrolls fine. I added one custom font to one of the TextView‘s and now it is choppy. I have tried both otf and ttf fonts.
Here is how I have code (simplified):
public class ItemAdapter extends ArrayAdapter<ItemObject> implements
SectionIndexer {
private Typeface myTypeface; // class variable
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_row_layout, parent,
false);
holder = new ViewHolder();
holder.t1 = (TextView) convertView.findViewById(R.id.itemName);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ItemObject io = getItem(position);
String name = io.name;
myTypeface = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/listitemfont.ttf");
holder.t1.setText(name);
holder.t1.setTypeface(myTypeface);
return convertView;
}
Is there a better way?
You are creating the same typeface every time
getView()is called, move this line into your constructor:And you probably don’t need to re-set the typeface every time either, just when the TextView is created.