import android.app.Activity; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView; import com.commons.widget.NetworkImageView; import com.geluyawangluo.withthenight.R; import java.util.ArrayList; import java.util.HashMap; public class CatAdapter extends BaseAdapter { private Context activity; private ArrayList<HashMap<String,String>> list; private TextView allPrice; private float allp=0; private ViewHolder holder; private ArrayList<Boolean> booList; public CatAdapter(Context activity, ArrayList<HashMap<String,String>> list, TextView allPrice,ArrayList<Boolean> booList) { this.activity = activity; this.list = list; this.allPrice=allPrice; this.booList=booList; allp=0; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); // return 5; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { holder = null; if (convertView == null) { holder = new ViewHolder(); convertView=((Activity) activity).getLayoutInflater().inflate(R.layout.layout_catlist,null); holder.nameTv = (TextView) convertView.findViewById(R.id.name); holder.image=(NetworkImageView) convertView.findViewById(R.id.image); holder.price = (TextView) convertView.findViewById(R.id.jiage); holder.num = (TextView) convertView.findViewById(R.id.shuliang); holder.box=(CheckBox)convertView.findViewById(R.id.box); holder.text1=(TextView)convertView.findViewById(R.id.text1); holder.text2=(TextView)convertView.findViewById(R.id.text2); holder.text3=(TextView)convertView.findViewById(R.id.text3); holder.text4=(TextView)convertView.findViewById(R.id.text4); holder.jiaBtn=(ImageView)convertView.findViewById(R.id.jiabtn); holder.jianBtn=(ImageView)convertView.findViewById(R.id.jianbtn); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.nameTv.setText(list.get(position).get("name")); holder.price.setText(list.get(position).get("price")); holder.image.setImageUri(list.get(position).get("img")); holder.num.setText(list.get(position).get("count")); holder.price.setText(list.get(position).get("price")); holder.text2.setText(list.get(position).get("shuxin2")); holder.text4.setText(list.get(position).get("shuxin1")); final float s=Float.valueOf(list.get(position).get("price")); final int nums= Integer.valueOf(list.get(position).get("count")); final float i=s*nums; holder.box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ booList.set(position,true); allp+=i; }else{ booList.set(position,false); allp-=i; } allPrice.setText("¥"+allp+""); } }); if(booList.get(position)==true){ holder.box.setChecked(true); allp+=i; }else{ holder.box.setChecked(false); allp-=i; if(allp<0){ allp=0; } } allPrice.setText("¥"+allp+""); // TODO Auto-generated method stub return convertView; } public class ViewHolder { TextView nameTv; NetworkImageView image; TextView price; TextView num; CheckBox box; TextView text1; TextView text2; TextView text3; TextView text4; ImageView jiaBtn; ImageView jianBtn; } class A { public static final int TYPE_CHECKED = 1; public static final int TYPE_NOCHECKED = 0; int type; public A(int type){ this.type = type; } } }