Florent Just Posted February 24, 2012 Share Posted February 24, 2012 Bonjour a tous, J'ai créé une application qui affiche une gallery d'image (et potentiellement ajouter des images en cliquant sur un bouton) Voici mon code public class ImgAdapteur extends BaseAdapter{ int GalItemBg; private Context cont; private ArrayList<Integer> maliste; public ImgAdapteur(Context c) { cont = c; maliste = new ArrayList<Integer>(); maliste.add(R.drawable.token_red); } public int getCount() { return maliste.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imgView = null; //Récyclage du composant if (convertView == null) imgView = new ImageView(cont); else imgView = (ImageView)convertView; imgView.setImageResource(this.maliste.get(position)); imgView.setLayoutParams(new Gallery.LayoutParams(50, 60)); imgView.setScaleType(ImageView.ScaleType.FIT_XY); return imgView; } public void AddToken(int token) { this.maliste.add(token); notifyDataSetChanged(); } } et l'appel de fonction ImgAdapteur Adapteurp1 = new ImgAdapteur(this); tokenp1 = (Gallery) findViewById(R.id.tokenp1); tokenp1.setAdapter(Adapteurp1); tokenp1.setSpacing(5); Mon problème : j'aimerai d'une part mettre un texte sur les images. d'autre part faire que mon ImgAdapteur gère une liste d'objet (par exemple qui contient une image et un texte) à la place d'une liste d'image Merci beaucoup Link to comment Share on other sites More sharing options...
arnouf Posted February 26, 2012 Share Posted February 26, 2012 Dans la méthode getView plutôt que de charger manuellement une ImageView, tu dois utiliser le procédé de layoutinflater afin de charger un de tes fichiers XML correspondant à la visualisation que tu attends pour chaque élément de ta gallery. Link to comment Share on other sites More sharing options...
Maraumax Posted March 6, 2012 Share Posted March 6, 2012 Et concernant ta première demande tu créer un objet Image avec les champs que tu souhaite (url, texte) Ensuite tu replace ton array de integer par un array de ta classe image. Après tu peut utiliser les méthodes de ta classe pour récupérer tel ou tel champ. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.