我怎样才能把不同颜色的ListView [英] how can i put different colors in ListView
本文介绍了我怎样才能把不同颜色的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得不同颜色的列表视图中的每一行
i want to get the different colors in each row of the list view
但当前只有一种颜色示
让我怎么能做到这一点。
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
请告诉我该怎么办
感谢
推荐答案
您可以使用匿名ArrayAdapter
你必须写code里面的 getView()
You can use anonymous ArrayAdapter
you have to write code inside getView()
ArrayAdapter<String> adapter=new ArrayAdapter<String>(
this,R.layout.main,R.id.textview1,titles){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(position ==condition){
convertView.setBackgroundResource(R.color.grey);}
else if(second condition){convertView.setBackgroundResource(R.color.something else);}
return view;};
};
另一种方法是
ANother approach is
为什么难道你不这样做定制的ListView?您可以管理视图按照您的要求在那里。
Why donot you do for Customized ListView? You can manage view as per your requirement there.
谢谢 迪帕克
这篇关于我怎样才能把不同颜色的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文