2011-07-11 6 views
1

Androidのリストアクティビティにカスタムフォントを設定しようとしています。私は成功し、それは一度アイテムがそうのように、クリックされます行うことができます。項目をクリックする前に、しかしAndroidのListActivityにフォントを設定する

@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); 
     } 

、フォントを割り当てることは何ら影響ありません:

// 
    // 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); 
    } 

デバッグを初期設定であることを示し、 GUIに表示され、mAnswerArrayに子があるにもかかわらず、ListView vにはゼロの子があります。

何が問題なのでしょうか?

+0

は、あなたが(無効に呼び出してみまし書体を設定した後、ListViewコントロールの上またはTextViewsのいずれか)? – mibollma

+0

ちょうど試しました - 違いはありません。 –

答えて

1

はviewBinderを設定し、そのように、あなたのアダプタでsetViewValueを上書き:

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); 
     } 
    } 
} 
+0

ありがとう - ArrayAdapterはsetViewBinderメソッドをサポートしていないようです。データベースフィールドをアダプタビューに接続するのは明らかです。 –

+0

おっと!詳細については、この記事をチェックしてください:http://stackoverflow.com/questions/5911198/custom-font-for-textview-in-arrayadapter –

+0

ありがとう、そのリンクはチケットだった –

関連する問題