在网上查到设置隔行隔色的如下实现方式。
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
public class CustomAdapter extends SimpleAdapter {
private int[] colors = new int[] { 0x30ff00ff, 0x30f6f6f6 };
/*
*以数字方式传入时,需按ARGB格式;若按RGB格式,不生效
*或数组中成员为 android.graphics.Color.rgb(230, 230, 230)
*/
public CustomAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
return view;
}
}