Question

Algorithme question ici.

Je crée une application qui montre un document juridique, avec des onglets pour la navigation (TOC, signets, etc.). A l'intérieur de l'onglet TOC, je dois montrer une table multi-niveaux de contenu. Lors de la « feuille » de la table des matières, je dois montrer un TextView

Alors, je pourrais avoir:

tab1: Liste -> Liste -> Liste -> Liste -> Liste -> TextView

ou

tab1: Liste -> Liste -> Liste -> TextView

ou

tab1: Liste -> TextView

en fonction du chapitre, section, sous-section, structure subsubsection du livre que je montre.

Maintenant, il ne importe comment vous êtes profondément, le TabHost doit être toujours présent, de fournir la navigation principale. (Oui, j'ai demandé, et je dois utiliser les onglets, pas de menu.)

La question:

Comment peut-on implémenter la liste récursive à l'intérieur du FrameLayout d'un onglet? Ou devrais-je utiliser un style ListView sous forme d'onglets et tout simplement pas utiliser le TabHost?

Idées?

Merci!
llappall

Était-ce utile?

La solution

Okay. Number one you cannot put ListViews inside ListViews, ScrollViews, GridViews or anything scrollable for that matter (i.e. a ListView item cannot be ListView). It might compile, it might run, but the results will not be what you expect or want. This is because a ListView cannot have a height which is set to WRAP_CONTENT.

You can have a two-level list (ExpandableListView) but if you require more levels than that you will have to implement the functionality yourself by extending ListView or ExpandableListView.

You can also have sectioned lists, and lists with multiple item types, but there is no way using the default SDK components to get a 5-level list.

Number two: Yes you can have a ListView inside a TabHost. You won't be able to use a ListActivity, but that just means you'll have to call the ListView methods directly:

ListView myList = findViewById(R.id.myList);
myList.setAdapter(myListAdapter);

instead of calling the inbuilt ListActivity methods.

Just place your ListView inside the FrameLayout in your layout file. If you have three tabs and the ListView is the first element inside the FrameLayout, then it will be displayed as the content for the first tab. If it is the second element, it will be the content for second tab and so on.

The only way you could implement a recursive list with inbuilt components would be to use a single ListView, and then change the contents of the adapter of the ListView when a user selects an item (essentially a drill-down menu using a single ListView). You'd also need to catch the back button with onBackPressed in order to allow the user to navigate back up the list, or provide a back button somewhere.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top