【发布时间】:2014-10-13 08:24:21
【问题描述】:
我需要在特定索引处动态更改ListView 的子视图的背景颜色。所以我需要在应用背景之前先获取视图。
我已经尝试了以下方法。
getViewAt(int index) - 这不适用于ListView。
getChildAt(int index) - 这会导致运行时 NPE 错误
Google 搜索返回不相关的结果。
请帮帮我。谢谢。
【问题讨论】:
-
您需要在自定义适配器的 getView 方法上执行此操作。检查位置是否与您要更改的位置相同并应用您的背景更改。
-
您可以使用 adapter.getView() 但您可能希望在 getView() 本身上这样做
-
listView.getChildAt(index);应该可以工作。显示代码和异常跟踪。 -
A Google search returns irrelevant results.我怀疑您是否真的搜索过,因为我搜索过并获得了很多的相关结果。
标签: android android-listview android-view