Baton Posted October 21, 2011 Share Posted October 21, 2011 Bonjour! J'aimerai créé une ListView perso vertical qui contiendrai entre autre une autre ListView mais horizontal :) Après pas mal de recherche je ne suis parvenu qu'a faire une ListView perso qui contient une image et du texte... Voici mon but : En natif dans Android c'est possible ou je rêve? Si c'est possible comment procédé? Ps : je crée ma liste avec un SimpleAdapter. Merci par avance. Link to comment Share on other sites More sharing options...
Sylvain-a Posted October 23, 2011 Share Posted October 23, 2011 Hum, ça me parait un peu farfelu mais bon ^^ Ton simpleAdapter, est ce que c'est une classe personnalisée qui étend de simpleAdapter? Car, personnellement pour instancier ça je pense qu'il faudrait que tu crées un adapter personnalisé qui étend de SimpleAdapter, et dans la méthode getView, tu charges ton image et ton texte, puis tu instancies ta listeView et tu appelles un SimpleAdapter (pas besoin d'un personnalisé cette fois) qui va se charger de générer ta seconde liste. Et as tu un maximum de 4 images ou est ce variable? (parce que si c'est constant, plutot que d'utiliser une seconde ListeView, tu devrais utiliser un LinearView) Mais bon, personnellement je ne suis pas sur que Android supporte deux ListView imbriquées Link to comment Share on other sites More sharing options...
Baton Posted October 24, 2011 Author Share Posted October 24, 2011 Merci pour ta réponse. Oui la seconde listview est dynamique... Je vais testé la solution que tu me propose. Si ce n'est pas possible que me conseils tu pour mettre en place ce fonctionnement? Re-codé une listview de A à Z (avec un FrameLayout)? Merci et bonne journée Link to comment Share on other sites More sharing options...
Baton Posted October 24, 2011 Author Share Posted October 24, 2011 Bon alors j'avance :) J'ai mis en place un ArrayAdapter qui affiche une image et deux texte via getView() Le problème c'est que quand je tente d'ajouté une Liste j'ai un null pointer exception :s. Pourtant dans la logique des choses tout se compile bien... Je cherche dans la bonne direction d'après vous ou je m'égare :)? Pour les plus motivé je poste le code :) Mon ArrayAdapter : public class ListViewPlus extends ArrayAdapter<LineList> { public ListViewPlus(Context context, int textViewResourceId, List objects) { super(context, textViewResourceId, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = li.inflate(R.layout.slideshow_list_item, null); } LineList ll = (LineList) getItem(position); if (ll != null) { TextView tvIem1 = (TextView)view.findViewById(R.id.titre); tvIem1.setText(ll.getTitle()); TextView tvIem2 = (TextView)view.findViewById(R.id.description); tvIem2.setText(ll.getDescription()); ImageView tvIem3 = (ImageView)view.findViewById(R.id.imagesync); tvIem3.setImageResource(ll.getImageSync()); ListView tvIem4 = (ListView)view.findViewById(R.id.list); tvIem4.setAdapter(ll.getList().getAdapter()); } return view; } } L'objet LineList : L’exception et lancé ici public class LineList { private String title; private String description; private int imageSync; private ListView list; private Context context; public LineList(String title,String description,int imageSync, ArrayList<HashMap<String, String>> data,Context context) { super(); this.context = context; this.setTitle(title); this.setDescription(description); this.setImageSync(imageSync); this.setList(data); } public void setList(ArrayList<HashMap<String, String>> data) { SimpleAdapter mSchedule = new SimpleAdapter(this.context, data, R.layout.slideshow_souslist_item, new String[] {"imgt"}, new int[] {R.id.imgt}); this.list.setAdapter(mSchedule); //NULL a cette ligne } } Et mon activity : public class SlidepadActivity extends Activity { ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map; map = new HashMap<String, String>(); map.put("imgt", String.valueOf(R.drawable.slide)); listItem.add(map); ArrayList<LineList> listRow = new ArrayList<LineList>(); listRow.add(new LineList("titre1","Desc 1",R.drawable.slide,listItem,this.getBaseContext())); listRow.add(new LineList("titre2","Desc 2",R.drawable.slide,listItem,this.getBaseContext())); listRow.add(new LineList("titre3","Desc 3",R.drawable.slide,listItem,this.getBaseContext())); ListView mList = (ListView) findViewById(R.id.listviewperso); mList.setAdapter( new ListViewPlus( this, R.layout.slideshow_list_item, listRow )); } Merci pour votre aide :) Link to comment Share on other sites More sharing options...
Baton Posted October 24, 2011 Author Share Posted October 24, 2011 Bon j'ai réussi a avoir quelque chose de plus ou moins correct. Le problème venais du fait que je stocké une ListView au lieu d'un ListAdapter. public void setListAdapter(ArrayList<HashMap<String, String>> data) { this.listAdapter = new SimpleAdapter(this.context, data, R.layout.slideshow_souslist_item, new String[] {"imgt"}, new int[] {R.id.imgt}); } Don c'est bon je vois mes deux listes imbriqué! :) Reste plus qu'a trouvé comment rendre la deuxième a scrolling horizontale Link to comment Share on other sites More sharing options...
chpil Posted October 24, 2011 Share Posted October 24, 2011 Tu as un NullPointerException parce qu'il semble que l'attribut list de ta classe LineList ne soit jamais initialisé D'ailleurs, en as-tu besoin, de cet attribut ? Il me semble qu'il te suffirait de stocker la référence sur le SimpleAdapter que tu crées Link to comment Share on other sites More sharing options...
Baton Posted October 24, 2011 Author Share Posted October 24, 2011 Posté en méme temps :) Pour ce qui est de la ListView Horizontal c'est impossible :s Bonne journée Link to comment Share on other sites More sharing options...
Sylvain-a Posted October 25, 2011 Share Posted October 25, 2011 http://stackoverflow.com/questions/3877040/how-can-i-make-a-horizontal-listview-in-android une solution détournée Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.