My vision is to create a color coded listView, where I want to have a slim colored bar in each item’s layout. This bar should be a certain color based on an int I pass to the activity. How do I create such a bar(essentially a filled rectangle) and set its color. Currently, I am using a custom layout for my list and using a SimpleAdapter with an ArrayList.
I know I will have to use
if (integerForColor == someNumber)
//set the color of the shape, bar
I am sure this is a simple thing that I simply cannot think of at the moment, or must be missing a fundamental. Thank you in advance for your effort.
EDIT 1:
Trying to decode some of the answers that were here, I realized that you guys need my code on how I am building my list:
public class AddScreen extends Activity implements OnClickListener,
OnItemClickListener, OnItemLongClickListener {
SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
ListView listthings;
public void onCreate(Bundle savedInstanceState) {
from = new String[] { "row_1", "row_2" };
to = new int[] { R.id.row1, R.id.row2 };
adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
from, to);
listthings.setAdapter(adapter);
}
I have added the getView() Method:
public View getView (int position, View convertView, ViewGroup parent){
convertView.setBackgroundColor(R.drawable.red);
return convertView;
//I have no inflater as of now...
}

EDIT 2: As per @huntsfromshadow ‘s suggestion, I have created a new activity and overridden the getView() method there.
//Imports
public class Adapter extends SimpleAdapter{
public Adapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
row.setBackgroundColor(0xFF0000FF);
return row;
}
}
Unfortunately, it still does not work.
Create a custom adapter and override getView. That is the point where you can do any complicated layout decisions based on values and logic.
A google search for custom adapter will give you a lot of resources.