答案 0 :(得分:1)
您可以使用自定义适配器,例如:
class MyBaseAdapter extends extends ArrayAdapter<DataModel> {
private LayoutInflater mInflater;
private List<DataModel> mItems;
public MyBaseAdapter(List<DataModel> data, Context context) {
super(context, R.layout.row_item, data);
this.mItems = data;
this.mInflater = LayoutInflater.from(context);
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = mInflater.inflate(R.layout.row_item, null);
}
// set background color
if (i%2 == 0) {
view.setBackgroundResource(R.color.color_light);
} else {
view.setBackgroundResource(R.color.color_dark);
}
// bind data here
return view;
}
// other adapter logic
}
希望有帮助。