2016-05-09 14 views
0

Hier ist mein Problem hinzu:Wie Automodelle in Marke

Ich mag einige Autos hinzufügen, um seine Marke im Zusammenhang wie:

CADILLAC CTS, SRX, ESCALADE.

CHEVROLET: CAMARA, CORVETTE, VOLT.

ich eine Marke von Vehicule und Zugang zu wählenden Namen in Textview zu modellieren wie:

       CADILLAC 

     -CTS 
     -SRX 
     -... 

Was soll ich verwenden? Array?

Dank für die Antwort

EDIT: Hier ist mein eigentlicher Code, ist es Rotz für die Marke und Modelle, aber es war einfacher, so zu erklären ...

try 
{ 

    JSONArray QCM = response.getJSONArray("QCM"); 

    for (int i = 0; i < QCM.length(); i++) { 
     JSONObject getQcmObject = QCM.getJSONObject(i); 

     //Récupère la question et la place dans un array 
     String questionGet = getQcmObject.getString("question"); 
     questionArray.add(questionGet); 

     //Récupère les choix de la quesiton 
     JSONArray choiceGet = getQcmObject.getJSONArray("choix"); 

     //Boucle qui permet d'ajouter les choix dans une listes 
     for (int x = 0; x < choiceGet.length(); x++) { 
      String choice = choiceGet.getString(x); 
      listOfChoice.add(choice); 
      System.out.println(listOfChoice); 
     } 
     multiMap.put(questionGet, listOfChoice); 
     listOfChoice.clear(); 


    } 
    Set<Map.Entry<String, ArrayList<String>>> setMap = multiMap.entrySet(); 
    // Get an iterator 
    Iterator<Map.Entry<String, ArrayList<String>>> iteratorMap = setMap.iterator(); 
    System.out.println("\nHashMap with Multiple Values"); 
    // display all the elements 
    while(iteratorMap.hasNext()) { 
     Map.Entry<String, ArrayList<String>> entry = 
       (Map.Entry<String, ArrayList<String>>) iteratorMap.next(); 
     String key = entry.getKey(); 
     List<String> values = entry.getValue(); 
     System.out.println("Key = '" + key + "' has values: " + values); 
    } 
} 

ich nicht bekommen kann Zugang zu Wert! Hier ist meine Log-Katze

05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Combien d'os contient le squelette humain?' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Quel est la couleur du cheval blanc d'Henri IV?' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Une hernie inguinale étranglée :' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Lors des traumatismes de l'abdomen, le viscère le plus souvent touché est:' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Quelles sont les normes de la glycémie pré-pondial?' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Pathologies psychiatriques' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'En fonction de l'agent vulnérant, les brûlures sont classées en quatre groupes. Lesquels?' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Dans le bilan pré-thérapeutique du cancer de l'endomètre, l'exploration la plus performante est:' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Dans la péritonite généralisée d'origine appendiculaire, lequel de ces signes est toujours absent?' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Les complications immédiates des brûlures électriques sont:' has values: [] 
05-10 11:50:34.223 23881-23881/lyceraymondpointcar.entinfo I/System.out: Key = 'Les myomes ont un effet délétère sur les paramètres de fertilité, s'ils sont:' has values: [] 
+0

erste, müssen Sie 'Multimap cars' nicht' Multimap > cars' erstellen. Zweitens müssen Sie keine temrary 'listOfChoice'-Liste erstellen und die Modelle mit dem gleichen (Marken-) Schlüssel versehen:' multiMap.put (questionGet, choice); ' –

+0

Wenn ich das tue, habe ich nur ein Modell in meinem Marke –

+0

Ja, ein seltsames Verhalten von 'entrySet'. Dieser Code funktioniert gut: 'für (String brand: cars.keySet()) { für (String-Modell: cars.get (Marke)) { System.out.println (" Key = '"+ Marke +"' hat Werte: "+ Modell); } } ' –

Antwort

1

Sie können Google-Guavas Multimap verwenden.

Multimap<String,String> cars = ArrayListMultimap.create(); 
cars.put("CADILLAC", "CTS"); 
cars.put("CADILLAC", "SRX"); 
cars.put("CADILLAC", "ESCALADE"); 
cars.put("CHEVROLET", "CAMARO"); 
cars.put("CHEVROLET", "CORVETTE"); 
cars.put("CHEVROLET", "VOLT"); 

Hier ist der Link https://github.com/google/guava/wiki/NewCollectionTypesExplained#multimap

+0

Sehr interessant, ich denke es ist was ich will! –

+0

@FriedrichDylan toll! Wenn Ihnen die Antwort wirklich gefällt, ist es schön, dafür zu stimmen. Wenn Sie denken, dass die Antwort Ihre Frage löst, sollten Sie sie akzeptieren.so kann ich mein Karma verdienen, danke) –

+0

Ich bin zurück, ich verstehe endlich, wie es funktioniert! es ist wirklich cool, aber nur eine frage, wie kann ich ihnen jetzt Zugang? –

0

Warum nicht ein Arraylist listOfBrand.

Und jedes Auto:

public class Car{ 

Brand carBrand; 
String carName; 
} 

public class Brand{ 

String brandName; 
ArrayList<Car> listOfCar; 
} 
Verwandte Themen