user1049280
user1049280

Reputation: 5236

getting listview children onCreate()

I put this code in the end of onCreate() method of ListActivity

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
}

it doesn't work because ListView has no childs yet - it's size 0; however .getAdapter().getCount() returns not 0.

What should i use instead of list.getChildAt(i) to make this code correct?


UPDATE: i think, this is what i need Formatting ListView Content During onCreate() method (getting ListView children) but i don't get the solution of that problem

Upvotes: 0

Views: 2927

Answers (1)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53667

The view is added to the adapter so instead of list.getChildAt(i) use lv.getAdapter().getView(i, null, null) to get the view

Upvotes: 2

Related Questions