2011-10-11 13 views
5

मैं एंड्रॉइड विकास के लिए नया हूं। मैं संपर्क सूची के समान सूची दृश्य खोज रहा हूं i.e दाईं ओर वर्णमाला इंडेक्सिंग पैनल वाली एक सूची है।एंड्रॉइड लिस्टव्यू जैसे आईफोन संपर्क सूची (सूची के दाईं ओर वर्णमाला)

धन्यवाद।

+0

हो सकता है यह आपकी मदद कर सकते हैं: http://stackoverflow.com/questions/7431110/replication-of-apples-search-in-android/7442438#7442438 –

उत्तर

4

वहाँ एंड्रॉयड में ऐसा कुछ नहीं आप के लिए है है कस्टम दृश्य बनाएँ। iphone-uitable-view-in-android और sideindex-for-android. से आज़माएं मैंने आईफोन बनाने के लिए इन दो लिंक से कोड का उपयोग किया है जैसे कि अक्षरों के साथ सूची।

+0

आपके मूल्यवान उत्तर के लिए बहुत बहुत धन्यवाद, मैं साइडइंडेक्स-एंड-एंड्रॉइड का उपयोग कर रहा हूं, यह ठीक काम करता है, लेकिन मैं iphone-uitable-view-in-android डाउनलोड करने में सक्षम नहीं हूं। –

+0

मुझे लगता है कि दूसरा लिंक तरफ अक्षरों के साथ सूची बनाने के लिए पर्याप्त होगा। प्रत्येक अक्षर के लिए दूसरे लिंक हेडर में सूची में नहीं हैं, आप इन लिंक का उपयोग करके प्रत्येक वर्णमाला के लिए शीर्षलेख बना सकते हैं http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android- 09/या https://github.com/commonsguy/cw-advandroid/tree/master/ListView। – anujprashar

+0

ठीक है एक बार फिर से धन्यवाद। –

0

(सैमसंग के संपर्कों को छोड़कर देखने) एंड्रॉयड में ऐसा कुछ नहीं

एंड्रॉयड में डिफ़ॉल्ट देशी संपर्क सूची की तरह तेजी से पुस्तक के साथ listview उपयोग कर रहा है वहाँ है

+0

वहाँ इस तरह किसी भी कस्टम सूची दृश्य है। –

+0

आप किसके बारे में बात कर रहे हैं? –

1

साइडिंडेक्स-फॉर-एंड्रॉइड में कोड इसकी तुलना में अधिक जटिल है।

मैंने लाइनरलाइट बनाया क्योंकि उस उदाहरण ने अक्षरों के लिए टेक्स्टव्यू उदाहरणों को जोड़ा और जोड़ा। लेकिन फिर मैंने उन्हें क्लिक करने योग्य बना दिया।

मेरे ऑनक्लिक() में, मुझे लगता है कि यह इन विचारों में से एक है और इससे टेक्स्ट प्राप्त करें।

जब मैंने अपनी सूची लोड की, तो मैंने कर्सर एडाप्टर में एक शब्दकोश सेट किया। SetSelection() विधि इस शब्दकोश से ऑफ़सेट प्राप्त करती है।

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; 
} 
संबंधित मुद्दे