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
| package fr.oranginaschweppes;
public class ListAvecImage extends BaseAdapter {
private ArrayList<String>magasins;
private Context mContext;
private LayoutInflater mInflater;
public ListAvecImage(Context context,ArrayList<String>magasins){
this.magasins = magasins;
this.mContext = context;
this.mInflater = LayoutInflater.from(mContext);
}
public int getCount() {
// TODO Auto-generated method stub
return magasins.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return magasins.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout layoutItem;
//(1) : Réutilisation des layouts
if (convertView == null) {
//Initialisation de notre item à partir du layout XML "personne_layout.xml"
layoutItem = (LinearLayout) mInflater.inflate(R.layout.list_image, parent, false);
} else {
layoutItem = (LinearLayout) convertView;
}
//(2) : Récupération des TextView de notre layout
TextView text = (TextView)layoutItem.findViewById(R.id.text);
//ImageView image = (ImageView)layoutItem.findViewById(R.id.img);
//(3) : Renseignement des valeurs
text.setText(magasins.get(position));
//On retourne l'item créé.
return layoutItem;
}
} |