Bonjour merci de votre réponse,
J'ai regardé les mutations, cela ne s'utilise pas juste avec des drawables ?
Désolé je suis débutant en programmation.
Par contre j'ai essayé de changer mon code en utilisant les ViewHolder. En creant une classe nouvelle classe.
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;
}
} |
J'obtiens toujours le même problème (check et uncheck un peu partout) sauf que cette fois mon:
System.out.println(banque.get(position).getLivret());
me renvoie bien le bon livret et pas un autre.
De plus qu'est ce qu'est "simple_list_item_single_choice" en implémentant ça je pourrais avoir accès à mes checkbox ?
Partager