0

i want to change color of listview (simple_list_item_2 adapter) children at specific positions programmatically. (here for example all items with a = lv.getCount();)

ListView lv = getListView();
int a = lv.getCount();
for (int i = 0; i < a; i++) {
            ((TextView) lv.getChildAt(i).findViewById(android.R.id.text1)).setTextColor(Color
                    .parseColor("#EEC900"));
}

getChildAt(); doesnt always work for me. in case of the list-item being out of sceen, getChild doesnt return a view or something.. isnt there a better solution instead if getChildAt?

4

1 回答 1

0

您必须在 Adapter 类中执行此操作。Android 缓存并重新循环列表视图中的视图以节省内存。所以没有你看不到的视图来改变颜色。

因此,例如,如果您有一个 arrayAdapter,您将覆盖 getView 函数并在那里运行您的检查:

@Override
    public View getView(int position, View view, ViewGroup parent) {
        // use "position" to determine which item you have.
        // Then set the properties of "view" which is your list row.

    }
于 2013-07-29T19:09:49.060 回答