I'm new to android development and i am facing an issue, I have a listview
that is filled using an Array adapter, i want to make odd rows (items) in the listview
has the color of 'red' for example and the even rows have the color of 'yellow'! how can i achieve this?
here is the code onCreate()
method:-
//defining list view
listView = (ListView)findViewById(R.id.listView);
//defining data array list to store retrieved data from database
data = new ArrayList<String>();
adapter=new ArrayAdapter<String(this,android.R.layout.simple_list_item_1, data);
listView.setAdapter(adapter);
onPostExecute()
method:-
protected void onPostExecute(ArrayList<ProductionCommentsTable> result) {
// TODO Auto-generated method stub
for (int i = 0; i < result.size(); i++) {
data.add("Date: " + result.get(i).getDate().substring(0, 10) + newline + newline +
"Item: " + result.get(i).getItem() + newline + newline +
result.get(i).getComments());
if ( i % 2 == 0) {
listView.setBackgroundColor(Color.RED);
} else {
listView.setBackgroundColor(Color.YELLOW);
}
}
adapter.notifyDataSetChanged();
Thanks in advance...