GoodsItem.java 2.43 KB
package com.fish.drp.div;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.drp.R;
import com.drp.mobliemall.utils.MathUtils;
import com.fish.drp.div.util.ImageLoaderUtil;
import com.xiniunet.sdk.drp.domain.OrderLine;


public class GoodsItem extends RelativeLayout {

	private Context context;
	private OrderLine orderLine;
	ImageView ivIcon;
	TextView tvDesc,tvPrice,tvCount,tv_item_spec;
	
	
	public GoodsItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public GoodsItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public GoodsItem(Context context,OrderLine orderLine) {
		super(context);
		this.context = context;
		this.orderLine = orderLine;
		init(context);
		setDate();
	}
	/**
	 * 初始化
	 **/
	private void init(Context ct) {
		View.inflate(ct, R.layout.layout_goods_item, this);
		ivIcon = (ImageView) findViewById(R.id.ic_icon);
		tvDesc = (TextView) findViewById(R.id.tv_desc);
		tvPrice = (TextView) findViewById(R.id.tv_price);
		tvCount = (TextView) findViewById(R.id.tv_count);
		tv_item_spec = (TextView) findViewById(R.id.tv_item_spec);
		
	}
	
	private void setDate(){
//		ivIcon.setImageResource(resId)
		ImageLoaderUtil.loadImg(orderLine.getPictureUrl(),
				ivIcon, context);
		tvDesc.setText(orderLine.getItemName());
		tvPrice.setText("¥ "+orderLine.getUnitPrice());
		tvCount.setText("x"+orderLine.getQuantity().intValue());
		StringBuffer specifAttr = new StringBuffer("");
		if(orderLine.getItem() != null){
			if (orderLine.getItem().getSpec1AttributeName() != null && !"".equals(orderLine.getItem().getSpec1AttributeName())){
				specifAttr.append(orderLine.getItem().getSpec1AttributeName()+" "+orderLine.getItem().getSpec1ValueName());
			}
			if (orderLine.getItem().getSpec2AttributeName() != null && !"".equals(orderLine.getItem().getSpec2AttributeName())){
				specifAttr.append("  "+orderLine.getItem().getSpec2AttributeName()+" "+orderLine.getItem().getSpec2ValueName());
			}
			if (orderLine.getItem().getSpec3AttributeName() != null && !"".equals(orderLine.getItem().getSpec3AttributeName())){
				specifAttr.append("  "+orderLine.getItem().getSpec3AttributeName()+" "+orderLine.getItem().getSpec3ValueName());
			}
			tv_item_spec.setText(specifAttr.toString());
	}
	}
	
}