我試圖在自定義可擴展列表視圖中使用自定義字體。但是,當我嘗試這樣做時,最初,當Viewpager片段(我使用它)加載時,文本和字體對於ExpandableListView不可見。自定義ExpandableListAdapter中的Android自定義字體
一旦我點擊可展開列表視圖中的空白文本,就會顯示文本和字體。這個問題似乎只發生在自定義字體上。如果我使用任何其他自定義功能,如更改textview的顏色等,它的效果很好。好心幫
請參閱進一步參考所附的圖片:
我的代碼自定義擴展的listadapter相關部分:
public class MyExpandableListAdapter extends SimpleExpandableListAdapter {
View cntView;
LayoutInflater inflater;
Context cxt;
TextView tvGrp, tvChild;
public MyExpandableListAdapter(Context context,
List<? extends Map<String, ?>> groupData, int groupLayout,
String[] groupFrom, int[] groupTo,
List<? extends List<? extends Map<String, ?>>> childData,
int childLayout, String[] childFrom, int[] childTo) {
super(context, groupData, groupLayout, groupFrom, groupTo, childData,
childLayout, childFrom, childTo);
cxt=context;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
super.getGroupView(groupPosition, isExpanded, convertView, parent);
View tmp;
if (convertView == null) { // if it's not recycled, initialize some attributes
tmp=new View(cxt);
inflater=(LayoutInflater)cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
tmp=inflater.inflate(R.layout.explistgroup, null);
}else{
tmp = (View)convertView;
}
tvGrp=(TextView) tmp.findViewById(R.id.rowTextView);
tvGrp.setTypeface(FontLoader.loadTypeface(cxt,R.raw.roboto_regular)); // This does not work. It shows a blank textview initially. Only after I click it, the typeface and the text come into effect
//tvGrp.setText("ambit"); -- This works well
return tmp;
}
感謝納塔利,但那並沒有幫助我。我遇到同樣的問題:(。請讓我知道,如果你能想出任何其他方式來解決這個問題。 – ambit