1

can you help me find out how can I make my ListView sub items have different colors for each one? Like the first will be white, and second black and it iterate this colors for each new sub item.

Can it be done? if yes, can you direct me on where to go about this?

thanks in advance!

Yosi199
  • 1,745
  • 4
  • 22
  • 47

1 Answers1

0

Your Activity related to the List.xml should extend from ListActivity class

inside onCreate method

    mInflater = (LayoutInflater) getSystemService(
            Activity.LAYOUT_INFLATER_SERVICE);

    data = new Vector<RowData>();//RowData should get you, your data
    CustomAdapter adapter = new CustomAdapter(this, R.layout.list,
            R.id.title, data);
    setListAdapter(adapter);

Add a new CustomAdapter class

public class CustomAdapter extends ArrayAdapter<RowData> {
    public CustomAdapter(Context context, int resource,
            int textViewResourceId, List<RowData> objects) {               
        super(context, resource, textViewResourceId, objects);
    }

    public View getView(int position, View convertView, ViewGroup parent) {   
        ViewHolder holder = null;

        if(position%2==0)
            convertView.setBackgroundColor(color.darker_gray);
}
Nipuna
  • 6,846
  • 9
  • 64
  • 87
  • Can you please explain a bit more about: data = new Vector();//RowData should get you, your data – Yosi199 Aug 31 '11 at 18:12