listview item 背景更迭变换

listview item 背景交替变换
private static int[] mColors = { R.drawable.itembg2, R.drawable.itembg1 };//要改变的背景




public class AltColorAdapter extends SimpleAdapter {
               
        public AltColorAdapter(Context context,
                List<? extends Map<String, ?>> data, int resource, String[] from,
                int[] to) {
            super(context, data, resource, from, to);
            // TODO Auto-generated constructor stub
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            int[] arrayOfInt = mColors;
            int colorLength = mColors.length;
            int selected = arrayOfInt[position % colorLength];
            View localView = super.getView(position, convertView, parent);
            localView.setBackgroundResource(selected);
            return localView;
        }
    }