2010-11-07 4 views
9

क्या कोई मुझे AlphabetIndexer का उपयोग एक कस्टम एडाप्टर के साथ कैसे उपयोग कर सकता है जो getView का उपयोग करता है? मेरे पास यह एक मानक एडाप्टर के साथ काम कर रहा है, लेकिन कस्टम एडाप्टर के साथ इसे कार्यान्वित करने का कोई संकेत नहीं है।कस्टम एडाप्टर के साथ वर्णमाला इंडेक्सर

धन्यवाद

+0

मैं यहां कुछ समान कर रहा हूं http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42

+0

यहां मैंने एंड्रॉइड में नमूना एप्लिकेशन बनाया है, जो आईफोन अल्फाबेटिकल के समान है इंडेक्सर http://mukeshyadav4u.blogspot.in/2012/06/alphabatical-indexer-in-android.html –

उत्तर

7

हाय यह मैं कैसे उपयोग AlphaIndexer

private final class ContactListItemAdapter extends ResourceCursorAdapter 
     implements SectionIndexer { 
    AlphabetIndexer alphaIndexer; 

    public ContactListItemAdapter(Context context, int layout, Cursor c) { 
     super(context, layout, c); 
     alphaIndexer = new AlphabetIndexer(c, NAME_COLUMN_INDEX, 
       " ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
      .... 
      a normal getView 
      .... 
    } 

    public int getPositionForSection(int section) { 
     return alphaIndexer.getPositionForSection(section); 
    } 

    public int getSectionForPosition(int position) { 
     return alphaIndexer.getSectionForPosition(position); 
    } 

    public Object[] getSections() { 
     return alphaIndexer.getSections(); 
    } 
} 

NAME_COLUMN_INDEX डेटाबेस स्कीमा में स्तंभ का सूचकांक है।

...

यदि यह आप क्या जरूरत नहीं है, कुछ कोड के बारे में जो वर्ग का विस्तार और इतने पर करने के लिए किया जाना चाहिए जोड़ें।

वैसे भी मुझे उम्मीद है कि इससे मदद मिलती है।

public Cursor swapCursor(Cursor c) { 
    // Create our indexer 
    if (c != null) { 
     mIndexer = new AlphabetIndexer(c, c.getColumnIndex(Books.TITLE), 
       " ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 
    } 
    return super.swapCursor(c); 
} 

बाकी सब कुछ रहता है @vsm का वर्णन करता है बस के रूप में:

+2

हैलो, मैं पूछना चाहता हूं: अगर मैं डेटाबेस से अपना आइटम नहीं प्राप्त करता तो मैं क्या कर सकता हूं – MoHaKa

8

आप अपने एडाप्टर के कर्सर प्रबंधन के लिए एक LoaderManager का उपयोग कर रहे हैं, तो आप एक छोटे से समायोजन करने और अपने एडेप्टर swapCursor विधि ओवरराइड करने के लिए चाहता हूँ।

+0

क्या आप कृपया प्रदान करेंगे मुझे इसे लागू करने के लिए एक डेमो ??? –

+0

क्या लागू करने के लिए एक डेमो? – twaddington

+0

असल में मैं वर्णमाला खोज के अनुसार वर्णमाला इंडेक्सर और फास्ट स्क्रॉल को कार्यान्वित करना चाहता हूं जैसे एंड्रॉइड में संपर्क सूची। तो यह कैसे करें ?? –