public class OrderListConfirmAdapter extends BaseAdapter {
/**
* 应用环境变量
**/
private Context mContext = null;
private List mListOrder = null;
private LayoutInflater listContainer = null;
public final class ViewHolder {
//主体点击区域
public LinearLayout llBody;
//订单类型图标
public ImageView ivType;
//订单类型文字
public TextView tvType;
//面积区域
public TableRow trArea;
//面积文字
public TextView tvArea;
//补贴区域
public TableRow trAllowance;
//补贴文字
public TextView tvAllowance;
//电话点击区域
public RelativeLayout rlPhone;
//客户姓名
public TextView tvName;
//佣金单价区域
public TableRow trCommision;
//佣金单价文字
public TextView tvCommision;
//进场日期
public TextView tvStartTime;
//安装地址
public TextView tvAddress;
//原工单编号区域
public LinearLayout llOriginalOrderNo;
//原工单编号文字
public TextView tvOriginalOrderNo;
//确认按钮
public RelativeLayout rlConfirm;
}
/**
* @param context 上下文对象
* @param mListOrder 数据源
*/
public OrderListConfirmAdapter(Context context, List mListOrder) {
this.mContext = context;
this.listContainer = LayoutInflater.from(this.mContext);
this.mListOrder = mListOrder;
}
@Override
public int getCount() {
return mListOrder.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = listContainer.inflate(R.layout.item_list_confirm_order, null);
holder = new ViewHolder();
holder.llBody = (LinearLayout) convertView.findViewById(R.id.item_confirm_ll_body);
holder.ivType = (ImageView) convertView.findViewById(R.id.item_confirm_iv_type);
holder.tvType = (TextView) convertView.findViewById(R.id.item_confirm_tv_type);
holder.trArea = (TableRow) convertView.findViewById(R.id.item_confirm_tr_area);
holder.tvArea = (TextView) convertView.findViewById(R.id.item_confirm_tv_area);
holder.trAllowance = (TableRow) convertView.findViewById(R.id.item_confirm_tr_allowance);
holder.tvAllowance = (TextView) convertView.findViewById(R.id.item_confirm_tv_allowance);
holder.rlPhone = (RelativeLayout) convertView.findViewById(R.id.item_confirm_rl_phone);
holder.tvName = (TextView) convertView.findViewById(R.id.item_confirm_tv_name);
holder.trCommision = (TableRow) convertView.findViewById(R.id.item_confirm_tr_commision);
holder.tvCommision = (TextView) convertView.findViewById(R.id.item_confirm_tv_commision);
holder.tvStartTime = (TextView) convertView.findViewById(R.id.item_confirm_tv_start_time);
holder.tvAddress = (TextView) convertView.findViewById(R.id.item_confirm_tv_address);
holder.llOriginalOrderNo = (LinearLayout) convertView.findViewById(R.id.item_confirm_ll_original_order_no);
holder.tvOriginalOrderNo = (TextView) convertView.findViewById(R.id.item_confirm_tv_original_order_no);
holder.rlConfirm = (RelativeLayout) convertView.findViewById(R.id.item_confirm_rl_confirm);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
OrderInfoEntity entity = (OrderInfoEntity) mListOrder.get(position);
//根据工单类型设置类型图标、类型文字、面积是否可见及数值
switch (entity.getOrderType()) {
case 290001:
holder.ivType.setImageResource(R.drawable.icon_fix);
holder.tvType.setText(mContext.getResources().getString(R.string.fix_yes));
holder.trArea.setVisibility(View.VISIBLE);
holder.tvArea.setText(entity.getArea());
break;
case 290002:
holder.ivType.setImageResource(R.drawable.icon_measure);
holder.tvType.setText(mContext.getResources().getString(R.string.measure_order));
holder.trArea.setVisibility(View.INVISIBLE);
break;
}
//根据内外部订单决定补贴和佣金单价是否显示
switch (entity.getOrderAttriFlag()) {
case "0":
holder.trAllowance.setVisibility(View.INVISIBLE);
holder.trCommision.setVisibility(View.GONE);
break;
case "1":
holder.trAllowance.setVisibility(View.VISIBLE);
holder.trCommision.setVisibility(View.VISIBLE);
holder.tvAllowance.setText(entity.getSubsidy());
holder.tvCommision.setText(entity.getTotalAmountCommission() + "");
break;
}
//根据是否有原工单号决定原工单栏是否可见
if ("".equals(entity.getOriginalOrderNo())) {
holder.llOriginalOrderNo.setVisibility(View.GONE);
} else {
holder.llOriginalOrderNo.setVisibility(View.VISIBLE);
holder.tvOriginalOrderNo.setText(entity.getOriginalOrderNo());
}
//设置姓名、日期、地址
holder.tvName.setText(entity.getCustomerName());
holder.tvStartTime.setText(entity.getCreateDate());
holder.tvAddress.setText(entity.getCustomerAdress());
//点击电话图标
holder.rlPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(OrderFragment.ACTION_CLICK_PHONE);
intent.putExtra("position",position);
mContext.sendBroadcast(intent);
}
});
//点击确认按钮
holder.rlConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(OrderFragment.ACTION_CLICK_CONFIRM);
intent.putExtra("position",position);
mContext.sendBroadcast(intent);
}
});
//点击item时
holder.llBody.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(OrderFragment.ACTION_CLICK_BODY);
intent.putExtra("position",position);
mContext.sendBroadcast(intent);
}
});
return convertView;
}
/**
* 列表刷新操作
*
* @param list 订单信息实例集合
*/
public void update(List list) {
this.mListOrder = list;
notifyDataSetChanged();
}
}
ListView的Adapter
最新推荐文章于 2022-07-22 13:32:56 发布