in getView(...) method
if (position == 0) {
view.setBackgroundResource(R.drawable.bg_list_even);
} else if (position == 1) {
view.setBackgroundResource(R.drawable.bg_list_odd);
} else...
Update::
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.row, null);
holder = new ViewHolder();
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.title = (TextView) view.findViewById(R.id.txttitle);
holder.description = (TextView) view.findViewById(R.id.txtdesc);
holder.title.setText("Title" + position);
holder.description.setText("Desc" + position);
//here set your color as per position
if (position == 0) {
view.setBackgroundResource(R.drawable.bg_list_even);
} else if (position == 1) {
view.setBackgroundResource(R.drawable.bg_list_odd);
}
return view;
}
holder class
public class ViewHolder {
public TextView title;
public TextView description;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…