2011-12-23 10 views
0

私は、ListViewコントロールはまだチャイルズを持っていないので、それは動作しませんListActivity)(のonCreateリストビューの子を取得

ListView list=getListView(); 
for (int i=0;i<list.getAdapter().getCount();i++) { 
    TextView tv= (TextView) list.getChildAt(i).findViewById(R.id.list_item); 
    tv.setTextColor(Color.RED); //i simplify this string for example 
} 

ののonCreate()メソッドの最後にこのコードを置く - それはサイズ0です。ただし、.getAdapter()。getCount()は0を返しません。

このコードを正しく作成するために、list.getChildAt(i)の代わりに何を使用しますか?


UPDATE:私は、これは私がFormatting ListView Content During onCreate() method (getting ListView children) 必要なものだと思いますが、取得するにはlist.getChildAt(i)使用lv.getAdapter().getView(i, null, null)の代わりに、私はビューをアダプタに追加された問題

答えて

2

の解を得ることはありません図

+0

ので、私はこれに自分のコードを変更: 'のために(。。I = 0をint型、iがgetListViewを(<)getAdapter()同様にgetCount(); iが++){ \tのTextViewテレビ=(のTextView)list.getAdapter( ).getView(i、null、null).findViewById(R.id.list_item);。 tv.setTextColor(Color.RED); } ' それはコンパイルされますが、何もしません。 – user1049280

+0

カスタムアダプターとgetView()メソッドの方がうまく作成できます。 –

+0

ok、ご協力いただきありがとうございます – user1049280

関連する問題