2011-10-11 3 views

Répondre

4

Il n'y a rien comme ça dans Android vous devez créer une vue personnalisée. Essayez de iphone-uitable-view-in-android et sideindex-for-android. J'ai utilisé le code de ces deux liens pour créer une liste semblable à l'alphabet avec des alphabets sur le côté.

+0

Merci beaucoup pour votre précieuse réponse, j'utilise sideindex-for-android, ça marche bien, mais je ne suis pas en mesure de télécharger iphone-uitable-view-in-android. –

+0

Je pense que le deuxième lien sera suffisant pour créer une liste avec les alphabets de chaque côté. Dans les en-têtes de lien deuxième pour chaque alphabet ne sont pas là dans la liste, vous pouvez créer un en-tête pour chaque alphabet en utilisant ce lien http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android- 09/ou https://github.com/commonsguy/cw-advandroid/tree/master/ListView. – anujprashar

+0

ok bien sûr encore une fois. –

0

il n'y a rien comme ça dans Android (sauf les contacts Samsung voir)

la valeur par défaut dans Android utilise listview avec défilement rapide comme la liste des contacts natif

+0

Y at-il de liste personnalisée comme ça. –

+0

dont vous parlez? –

1

Le code de sideindex-for-android est plus complexe qu'il ne devrait l'être.

J'ai créé le LinearLayout comme cet exemple l'a fait et ajouté des occurrences TextView pour les lettres. Mais alors je les avais cliquables.

Dans mon onClick(), je vois si c'est l'une de ces vues et obtenir le texte.

Lorsque j'ai chargé ma liste, j'ai créé un dictionnaire dans l'adaptateur de curseur. La méthode setSelection() obtient le décalage de ce dictionnaire.

public static final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 

public Map<String, Integer> getAlphabetOffsets() { 

    HashMap<String, Integer> map = new HashMap<>(); 

    // First initialize the dictionary with all of the letters of the alphabet. 
    // 
    for (int idx = 0; idx < alphabet.length(); idx++) { 
     String aLetter = alphabet.substring(idx, idx+1); 
     map.put(aLetter, -1); 
    } 

    int numFound = cursor.getCount(); 

    cursor.moveToFirst(); 

    // Now go through the products' first initials and, when an initial has not been 
    // found, set the offset for that letter. 
    // 
    for (int idx = 0; idx < numFound; idx++) { 

     String productName = cursor.getString(cursor.getColumnIndex(DB.PRODUCTS_NAME_COL)); 

     String current; 

     if (productName == null || productName.equals("")) { 
      current = "0"; 
     } else { 
      current = productName.substring(0, 1).toUpperCase(); 
     } 

     // By the way, what do we do if a product name does not start with a letter or number? 
     // 
     // For now, we will ignore it. We are only putting 0-9 and A-Z into the side index. 
     // 
     if (map.containsKey(current) && map.get(current) < 0) 
      map.put(current, idx); 

     cursor.moveToNext(); 
    } 

    map.put("0", 0); 

    int lastFound = 0; 

    /* 
    Now we deal with letters in the alphabet for which there are no products. 

    We go through the alphabet again. If we do not have an offset for a letter, 
    we use the offset for the previous letter. 

    For example, say that we do not have products that start with "B" or "D", we 
    might see: 

      { "9" = 0, "A" = 1, "B" = -1, "C" = 5, "D" = -1, "E" = 10 } 

    After this runs, will we have: 

      { "9" = 0, "A" = 1, "B" = 1, "C" = 5, "D" = 5, "E" = 10 } 

    This is so if we click on B, we see the list starting a "A" and see that 
    there are no "B" products. 

    */ 
    for (int idx = 0; idx < alphabet.length(); idx++) { 

     String current = alphabet.substring(idx, idx+1); 

     if (map.get(current) < 0) { 
      map.put(current, lastFound); 
     } else { 
      lastFound = map.get(current); 
     } 
     System.out.println("alphabet \"" + current + "\" = " + map.get(current)); 
    } 

    return map; 
} 
Questions connexes