jump to navigation

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;

}

Comments»

1. swapna - January 15, 2010

here is the list of rgb colors
for android


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.