Custom ListView Colors in Android December 22, 2009
Posted by hunterp in Uncategorized.trackback
Hey. This is the easiest way to get custom colors onto a list. Basically, if the list entry is greater than 2, it will have a\
different color. The algorithm can be whatever you choose.
ListView fileList = (ListView)findViewById(R.id.list);
final String whatever[] = {“1″,”2″,”3″,”4″,”5″};
fileList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,rev) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = layoutInflater.inflate(android.R.layout.simple_list_item_1,null);
TextView i = (TextView)v.findViewById(android.R.id.text1);
i.setText(whatever[position].toString());
i.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
i.setBackgroundColor(Integer.parseInt(whatever[position]) > 2 ? Color.BLACK : Color.rgb(0xFF, 0xA5, 0×00));
return i;
}
here is the list of rgb colors
for android