vince123 Posted June 18, 2010 Share Posted June 18, 2010 Bonjour à tous, j'utilise un ExpandableListView qui a 5 parents, je veux qu'un seul des parents (et toujours le même) aie un enfant ! chaque parent contient une flèche et un titre ! Lorsque je clique sur le parent (qui a l'enfant) la flèche pivote de 90° et l'enfant s'affiche (jusqu'ici aucun problème ;) ) Mais lorsque je clique sur les autres parents (qui n'ont pas d'enfant) ma flèche pivote quand même :/ Que faire pour m'en sortir sachant que j'ai les conditions suivantes .. :| Pour mes flèches qui sont personnalisées je fais ça : dans mon .xml de l'activity : android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/relative" android:drawSelectorOnTop="false" android:groupIndicator="@drawable/expander_group"/> dans drawable => j'ai mon expander_group.xml où je déclare mes 2 flèches : android:state_expanded="true" android:drawable="@drawable/expander_ic_maximized" /> android:drawable="@drawable/expander_ic_minimized" /> Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted June 19, 2010 Share Posted June 19, 2010 setOnGroupExpandListener collapseGroup :P à mon avis, le Listener est appelé avant que la flèche ait pivoté Quote Link to comment Share on other sites More sharing options...
vince123 Posted June 20, 2010 Author Share Posted June 20, 2010 (edited) setOnGroupExpandListenercollapseGroup :P à mon avis, le Listener est appelé avant que la flèche ait pivoté oui tu as certainement raison merci, je testes cela lundi :P edit : A quel moment, je lui dis que je veux que tel et tel groupe (parent) n'ai pas d'enfant : getExpandableListView().setOnGroupClickListener(new OnGroupClickListener() { public boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) { getExpandableListView().collapseGroup(groupPosition); return false; } }); Edited June 21, 2010 by vince123 Quote Link to comment Share on other sites More sharing options...
superseed77 Posted July 6, 2010 Share Posted July 6, 2010 (edited) oui tu as certainement raison merci, je testes cela lundi :P edit : A quel moment, je lui dis que je veux que tel et tel groupe (parent) n'ai pas d'enfant : getExpandableListView().setOnGroupClickListener(new OnGroupClickListener() { public boolean onGroupClick(ExpandableListView parent, View v,int groupPosition, long id) { getExpandableListView().collapseGroup(groupPosition); return false; } }); un petit up sur cette question je ne vois pas où intervenir dans le code pour supprimer cette flêche, ici le code traite du clic pas de la constuction de la liste as-tu résolu ton problème ? Edited July 6, 2010 by superseed77 Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted July 6, 2010 Share Posted July 6, 2010 setGroupIndicator(Drawable groupIndicator) Quote Link to comment Share on other sites More sharing options...
superseed77 Posted July 6, 2010 Share Posted July 6, 2010 setGroupIndicator(Drawable groupIndicator) setGroupIndicator(Drawable groupIndicator) c'est pour supprimer la fleche sur l'ensemble de la liste ? n'est-ce pas pour un groupe vide j'imagine qu'il faut étendre ou modifier l'adapter : SimpleExpandableListAdapter BaseExpandableListAdapter et de faire quelque chose dans getGroupView du genre if(getChildrenCount(groupPosition)==0) mais comment ? :mad: ViewGroup Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted July 6, 2010 Share Posted July 6, 2010 Fais ton propre adapter, ca sera moins compliqué Quote Link to comment Share on other sites More sharing options...
superseed77 Posted July 6, 2010 Share Posted July 6, 2010 Fais ton propre adapter, ca sera moins compliqué As-tu un exemple stp j'étends la classe SimpleExpandableListAdapter et j'implemente la methode quoi où est-ce que je met l'état et l'indicator Quote Link to comment Share on other sites More sharing options...
superseed77 Posted July 6, 2010 Share Posted July 6, 2010 j'ai créé un expander_group.xml <?xml version="1.0" encoding="utf-8"?> android:state_expanded="true" android:state_empty="false" android:drawable="@drawable/arrow_li_parent_open" /> android:state_expanded="false" android:drawable="@drawable/arrow_li_parent_close" /> android:state_expanded="false" android:state_empty="true" android:drawable="@drawable/empty"/> android:state_expanded="true" android:state_empty="true" android:drawable="@drawable/empty"/> et chargé ça dans mon ExpandableListActivity Drawable icon = this.getResources().getDrawable(R.drawable.expander_group); getExpandableListView().setGroupIndicator(icon); j'ai bien mes icones mais l'icone ne disparait que quend je clique sur le groupe vide Allez les françophones de l'aide ! Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted July 6, 2010 Share Posted July 6, 2010 non, je pensais plutôt utiliser le BaseAdapter, et faire tes vues à la main :P Quote Link to comment Share on other sites More sharing options...
superseed77 Posted July 6, 2010 Share Posted July 6, 2010 non, je pensais plutôt utiliser le BaseAdapter, et faire tes vues à la main :P Ok merci excuse mais je suis encore débutant donc BaseAdapter et vues à la main je construit un LinearLayout que je sette dans getView du baseadapter ? Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted July 7, 2010 Share Posted July 7, 2010 Tu peux utiliser un layout xml, c'est mieux. this.getLayoutInflater.inflate(R.layout.toto, null) Mais je te conseille d'apprendre à te servir de BaseAdapter. C'est super utile! Il y a un tuto sur le site officiel. Quote Link to comment Share on other sites More sharing options...
superseed77 Posted July 7, 2010 Share Posted July 7, 2010 (edited) ok merci je comprend enfin, ça à l'aire plus souple je vais faire comme tu dis http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html Edited July 7, 2010 by superseed77 Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted July 7, 2010 Share Posted July 7, 2010 il faut utiliser un BaseAdapter ListActivity.setListAdapter() la méthode la plus compliquée est getView http://stackoverflow.com/questions/1320478/how-to-load-the-listview-smoothly-in-android n'oublie pas getItemViewType et getViewTypeCount Quote Link to comment Share on other sites More sharing options...
vince123 Posted July 7, 2010 Author Share Posted July 7, 2010 (edited) oui problème résolu : gestion des clicks sur les parents ! 1er parent => case 0 => démarrer intent...etc 2ème parent => pas de case 1 => montre les enfants 3eme parent, 4eme ...etc démarrer intent getExpandableListView().setOnGroupClickListener(new OnGroupClickListener() { public boolean onGroupClick(ExpandableListView parent,View v, final int groupPosition, long id) { if(!(groupPosition == 1)) { switch (groupPosition) { case 0: Intent x break; case 2: Intent xx break; case 3: Intent xxx break; case 4: Intent xxxx break; } return true; } else { return false; } } }); D'ailleurs voici la liste de mes enfants et j'aimerai mettre un string à la place de "go", comment faire ? :/ : static final String shades[] = { "lightgrey" , "go" , "yellow 1" , "indianred 1" , "lightgrey", }; Edited July 7, 2010 by vince123 Quote Link to comment Share on other sites More sharing options...
akex Posted July 13, 2010 Share Posted July 13, 2010 En faisant comme ça par exemple : string go = getString(R.string.go); Quote Link to comment Share on other sites More sharing options...
vince123 Posted July 13, 2010 Author Share Posted July 13, 2010 En faisant comme ça par exemple : string go = getString(R.string.go); Akex, merci, mais c'est résolu ;) ;) Quote Link to comment Share on other sites More sharing options...
akex Posted July 13, 2010 Share Posted July 13, 2010 Ben faut le dire alors :p T'as un example ExpandableListView. Je sèche sur les examples :(. Quote Link to comment Share on other sites More sharing options...
vince123 Posted July 19, 2010 Author Share Posted July 19, 2010 Ben faut le dire alors :pT'as un example ExpandableListView. Je sèche sur les examples :(. excuse moi, de n'avoir pu répondre plus tôt ! :| :| Regarde ici : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/index.html Ensuite dans "Lists" et plus particulièrement "4. ListAdapter" et "6. ListAdapter Collapsed" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.