如何在 ListView 中添加不同的颜色
我想在列表视图的每一行中获得不同的颜色
,但当前仅显示一种颜色
,所以我该怎么做,
ArrayAdapter<String> adapter=new ArrayAdapter<String(this,R.layout.latesthappenings,R.id.LH_Titles,titles);
setListAdapter(adapter);
我想在每一行中获得不同的颜色,
请告诉我该怎么做,
谢谢
i want to get the different colors in each row of the list view
but current only one color is shown
so how can i do this
ArrayAdapter<String> adapter=new ArrayAdapter<String(this,R.layout.latesthappenings,R.id.LH_Titles,titles);
setListAdapter(adapter);
i want to different color in each row
please tell how can i do
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
匿名ArrayAdapter
,您必须在getView()
Sudo代码
中编写代码另一种方法是
为什么不为自定义ListView做呢?您可以根据您的要求管理视图。
有一个 自定义 ArrayAdapter
谢谢
迪帕克
You can use
anonymous ArrayAdapter
you have to write code insidegetView()
Sudo code
ANother approach is
Why donot you do for Customized ListView? You can manage view as per your requirement there.
Have a Custom ArrayAdapter
Thanks
Deepak
在数组中设置所有不同的颜色(列表中所需的)代码,并从该数组中为每个行位置获取颜色代码,并使用 setBackgroundColor() 方法将该背景颜色设置为列表行。
试试这个。
Set all the different colors (that you want in your list) codes in an array and fetch color code from that array for each row position and use setBackgroundColor() method to set that background color to the list row.
Try this.