@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
項目顏色隨機變化。任何人都可以幫我解決..?Android - 滾動列表視圖時出現問題
是否在滾動時出現黑色? – 2013-03-13 06:03:47
不,藍色和灰色隨機出現。 – Arulkannan 2013-03-13 06:07:16