public class HLCheckAdapter extends BaseAdapter {

     private List<HuoLiang> list;
private Context context;
private int item;
private LayoutInflater inflater; public HLCheckAdapter(List<HuoLiang> list, int item, Context context) {
this.list = list;
this.item = item;
this.context = context;
this.inflater = LayoutInflater.from(context);
} @Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
} @Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
} @Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(item, null);
holder = new ViewHolder();
holder.dianmian = (TextView) convertView
.findViewById(R.id.dianmain);
holder.agent_cargo_charge = (TextView) convertView
.findViewById(R.id.agent_cargo_charge);
holder.total_price = (TextView) convertView
.findViewById(R.id.total_price);
holder.shuliang = (TextView) convertView
.findViewById(R.id.shuliang);
holder.quantity = (TextView) convertView
.findViewById(R.id.quantity);
holder.no = (TextView) convertView.findViewById(R.id.number);
convertView.setTag(holder);
} else {
// viewHolder被复用
holder = (ViewHolder) convertView.getTag();
}
String dianmian = list.get(position).getDianmian();
String total_price = list.get(position).getTotal_price();
String agent_cargo_charge = list.get(position).getAgent_cargo_charge();
String shuliang = list.get(position).getShuliang();
String quantity = list.get(position).getQuantity();
String number = position + 1 + "";
holder.no.setText(number);
holder.dianmian.setText(dianmian);
holder.total_price.setText(total_price);
holder.agent_cargo_charge.setText(agent_cargo_charge);
holder.shuliang.setText(shuliang);
holder.quantity.setText(quantity);
holder.no.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
holder.dianmian.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);// 第一个参数:字体类型、第二个参数字体风格 holder.total_price.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC );//粗斜体
holder.agent_cargo_charge.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC );
holder.shuliang.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC );
holder.quantity.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC );
// 为listView设置隔行变色
if (position % 2 == 0) {
convertView.setBackgroundResource(R.drawable.item_selector);
} else {
convertView.setBackgroundResource(R.drawable.item_selector1);
} return convertView;
} private class ViewHolder {
private TextView dianmian;
private TextView total_price;
private TextView agent_cargo_charge;
private TextView shuliang;
private TextView quantity;
private TextView no;
}
}

item_selector.xml

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="false" android:drawable="@color/itemnormal1"></item> </selector>

item_selector1.xml

 <?xml version="1.0" encoding="utf-8"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@color/itemnormal2"></item>
</selector>

隔行变色设置的颜色:

 <color name="itemnormal1">#F8F8F8</color>
<color name="itemnormal2">#D8EBEF</color>
05-11 03:50