package org.jgw.onepai.adapter; import java.util.List; import org.jgw.onepai.R; import org.jgw.onepai.bean.Article; import org.jgw.onepai.bean.Worker_cart; import SysCommon.util.IBaseAdapter; import SysCommon.util.Tools; import android.content.Context; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.view.ViewGroup; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; public class Worker_cartAdapter extends IBaseAdapter { public Worker_cartAdapter(Context context,List<Worker_cart> arts, int item_resource) { super(context, arts, item_resource); } public final class q_ReduceOnClickListener implements OnClickListener { private int i_pos; private TextView textview_q; public q_ReduceOnClickListener(int position,TextView tv) { this.i_pos=position; this.textview_q=tv; } public void onClick(View v) { // TODO Auto-generated method stub Worker_cart cart=(Worker_cart)lists.get(i_pos); cart.CURR_q=cart.CURR_q -1; this.textview_q.setText(Float.toString(cart.CURR_q)); } } public final class q_IncreaseOnClickListener implements OnClickListener { private int i_pos; private TextView textview_q; public q_IncreaseOnClickListener(int position,TextView tv) { this.i_pos=position; this.textview_q=tv; } public void onClick(View v) { // TODO Auto-generated method stub Worker_cart cart=(Worker_cart)lists.get(i_pos); cart.CURR_q=cart.CURR_q + 1; this.textview_q.setText(Float.toString(cart.CURR_q)); } } public View getView(int position, View convertView, ViewGroup parent) { ImageView imgView=null; TextView textView=null; TextView textView_retail_price=null; TextView editText_q=null; ImageView img_r=null; ImageView img_i=null; if(convertView==null) { convertView=inflater.inflate(this.item_resource, null); imgView=(ImageView)convertView.findViewById(R.id.worker_cart_item_img); textView=(TextView)convertView.findViewById(R.id.worker_cart_item_article_name); textView_retail_price=(TextView)convertView.findViewById(R.id.worker_cart_item_retail_price); editText_q=(TextView)convertView.findViewById(R.id.worker_cart_item_q); img_r=(ImageView)convertView.findViewById(R.id.worker_cart_item_btn_reduce_q); img_i=(ImageView)convertView.findViewById(R.id.worker_cart_item_btn_increase_q); ViewCache cache=new ViewCache(); cache.imgView=imgView; cache.textView=textView; cache.textView_retail_price=textView_retail_price; cache.editText_q=editText_q; cache.img_r=img_r; cache.img_i=img_i; convertView.setTag(cache); } else { ViewCache cache=(ViewCache)convertView.getTag(); imgView=cache.imgView; textView=cache.textView; textView_retail_price=cache.textView_retail_price; editText_q=cache.editText_q; img_r=cache.img_r; img_i=cache.img_i; } img_r.setOnClickListener(new q_ReduceOnClickListener(position,editText_q)); img_i.setOnClickListener(new q_IncreaseOnClickListener(position,editText_q)); Worker_cart cart=(Worker_cart)this.lists.get(position); Article art=cart.CURR_article; try { textView.setText(art.CURR_article_name); textView_retail_price.setText("¥:"+art.CURR_retail_price); editText_q.setText(Float.toString(cart.CURR_q)); if(null==art.img) { art.img=Tools.GetImageFromRestful(art.CURR_img); } imgView.setImageBitmap(art.img); } catch (Exception e) { Tools.Log(e.getMessage()); } return convertView; } private final class ViewCache{ public ImageView imgView; public ImageView img_r; public ImageView img_i; public TextView textView; public TextView textView_retail_price; public TextView editText_q; } }
红色字体是关键部分