1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
public class MyAdapter extends BaseAdapter {
List<Banque> banque;
LayoutInflater inflater;
public MyAdapter(Context context,List<Banque> banque) {
inflater = LayoutInflater.from(context);
this.banque = banque;
}
public int getCount() {
// TODO Auto-generated method stub
return banque.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return banque.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
private class ViewHolder {
ImageView logo;
TextView livret;
CheckBox checkBox;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.listebanque, null);
holder.logo = (ImageView) convertView.findViewById(R.id.logoBanque);
holder.livret = (TextView) convertView.findViewById(R.id.livretBanque);
holder.checkBox = (CheckBox) convertView.findViewById (R.id.checkBanque);
convertView.setTag(holder);
holder.checkBox.setTag(banque.get(position));
}else
holder = (ViewHolder) convertView.getTag();
holder.logo.setImageBitmap(banque.get(position).getLogo());
holder.livret.setText(banque.get(position).getLivret());
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
if(buttonView.isChecked())
System.out.println(banque.get(position).getLivret());
else
System.out.println("unselected");
}
});
return convertView;
}
} |