【发布时间】:2014-01-27 03:53:25
【问题描述】:
我从 .txt 文件中读取值并使用 ArrayAdapter 将它们放入 GridView 中,它运行良好。 但我想根据项目的价值改变项目的颜色。
例如: 1 是灰色 2是红色 3是蓝色 4是...
但我无法更改 GridView 中单个项目的背景颜色,只能更改整个 GV。
GridView gv = (GridView) findViewById(R.id.gvSpeelveld);
gv.setBackgroundColor(Color.GREEN);
此尝试不成功
//View is null
View v = gv.getChildAt(2);
v.setBackgroundColor(Color.CYAN);
但是我怎样才能获得单个 gridView 的不同项目呢? for 循环会非常有用。
【问题讨论】:
-
您必须在 Adapter 的
getView()方法中为单个项目设置背景...
标签: android gridview colors items