@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
LinearLayout root_view = (LinearLayout) row
.findViewById(R.id.list_root_view);
int evenRow = position % 2;
if (evenRow == 0) {
root_view.setBackgroundColor(context.getResources().getColor(
android.R.color.darker_gray));
}
holder = new ViewHolder();
holder.date = (TextView) row.findViewById(R.id.dateTextView);
holder.time = (TextView) row.findViewById(R.id.timeTextView);
holder.breachNo = (TextView)row.findViewById(R.id.breachNoTextView);
holder.fee = (TextView) row.findViewById(R.id.feeTextView);
holder.orderCheckBox =CheckBox)row.findViewById(R.id.orderCheckBox);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
historyData = arraylist.get(position);
holder.date.setText(historyData.getDate() + "");
holder.time.setText(historyData.getTime().toString());
holder.breachNo.setText(historyData.getBreachNo() + "");
holder.fee.setText(historyData.getFee() + "");
holder.orderCheckBox.setEnabled(true);
return row;
}
在上面的代码中我有一些问题。我想listview
交替设置我的项目颜色。(例如蓝色的奇数行和灰色的偶数行)。在加载活动时,我得到了完美的颜色。问题是滚动我 listview
的项目颜色随机变化。谁能帮我解决..?