Reputation: 36683
I'm trying to set a custom font on a list activity in Android. I can successfully do it once an item gets clicked, like so:
@Override
protected void onListItemClick(ListView listView, View listItemView,
int position, long id) {
int childCount = listView.getChildCount();
for (int i = 0; i < childCount; i++) {
TextView c = (TextView) listView.getChildAt(i);
c.setTypeface(mTypeFace);
}
However, before the item is clicked, assigning a font has no impact:
//
// Create the adapter to display the choice list
//
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.simple_list_item_single_choice_custom,
mAppState.mAnswerArray) {
};
/* attach the adapter to the ListView */
setListAdapter(adapter);
ListView v = getListView();
int childCount = v.getChildCount();
for (int i = 0; i < childCount; i++) {
TextView c = (TextView) v.getChildAt(i);
c.setTypeface(mTypeFace);
}
Debugging show that in the initial setup, the ListView v has zero children, despite the fact they show up in the GUI and mAnswerArray has the children.
Any idea what the problem might be?
Upvotes: 1
Views: 1590
Reputation: 15390
Set the viewBinder and override the setViewValue in your adapter, like so:
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(columnIndex == 7){
TextView textView = (TextView) view;
textView.setTypeface(gotham_book);
}
}
}
Upvotes: 1