2010-10-10 14 views
15

क्या सूची आइटम में नए आइटम जोड़े जाने के बाद सेक्शनइंडेक्सर को पुन: अनुक्रमणिका करने का कोई तरीका है?पुन: अनुक्रमणिका/एक अनुभाग इंडेक्सर रीफ्रेश करें

मुझे यह solution मिला, लेकिन धारा इंडेक्सर रीफ्रेश होने के बाद ओवरले को शीर्ष बाएं कोने में स्थिति है।

किसी के पास कोई विचार है?

+0

द्वारा ListView के लिए वर्गों सूची पुन: लोड मैं कुछ कर रहा हूँ मजबूर कर सकते हैं समान यहाँ http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42

उत्तर

4

एक बार FastScroller (अपने AbsListView वर्ग कि ListView तक फैली हुई है में) SectionIndexer#getSections() फोन करके अपने वर्गों प्राप्त करता है, यह कभी नहीं उन्हें फिर से प्राप्त जब तक आप को सक्षम/अक्षम लिंक आप का उल्लेख में उल्लेख की तरह तेजी से स्क्रॉल। स्क्रीन पर मूल्य प्रदर्शित करने के लिए, फास्टस्क्रॉलर अनुभाग की टूस्ट्रिंग विधि को कॉल करता है। यदि वर्गों अंग्रेजी का प्रतिनिधित्व करते हैं,

  • वर्गों सरणी निश्चित लंबाई (वर्गों की अपेक्षित संख्या की अधिकतम लंबाई की है उदाहरण के लिए:

    एक संभावित समाधान के लिए एक कस्टम SectionIndexer है कि निम्नलिखित विशेषताएं है। वर्णमाला यह 26 हो जाएगा)

  • बल्कि तार
  • का उपयोग कर ओवरराइट करें अपना कस्टम अनुभाग वस्तु की toString विधि क्या आप वर्तमान 'अनुभाग मूल्यों' पर आधारित चाहते प्रदर्शित करने के लिए की तुलना में, वर्गों का प्रतिनिधित्व करने के लिए एक कस्टम वस्तु है।
  • -

उदा। अपने कस्टम SectionIndexer

private int mLastPosition; 

public int getPositionForSection(int sectionIndex) { 
    if (sectionIndex < 0) sectionIndex = 0; 
    // myCurrentSectionLength is the number of sections you want to have after 
    // re-indexing the items in your ListView 
    // NOTE: myCurrentSectionLength must be less than getSections().length 
    if (sectionIndex >= myCurrentSectionLength) sectionIndex = myCurrentSectionLength - 1; 
    int position = 0; 
    // --- your logic to find the position goes in here 
    // --- e.g. see the AlphabeticIndexer source in Android repo for an example 

    mLastPosition = position; 
    return mLastPosition; 
} 

public Object[] getSections() { 
    // Assume you only have at most 3 section for this example 
    return new MySection[]{new MySection(), new MySection(), new MySection()}; 
} 

// inner class within your CustomSectionIndexer 
public class MySection { 
    MySection() {} 

    public String toString() { 
     // Get the value to displayed based on mLastPosition and the list item within that position 
     return "some value"; 
    } 
} 
1

में मैंने पाया setContentView(R.layout.whatever) कॉल करने के लिए और फिर अपने नए एडाप्टर/नए डेटा आइटम के साथ फिर से पॉप्युलेट ListView है कि यह करने के लिए सबसे अच्छा तरीका है। यह आपके नए आइटम के साथ ListView को फिर से चलाएगा और फास्टस्क्रॉल ओवरले सही जगह पर दिखाई देगा।

0

मैं notifyDataSetInvalidated पाया ठीक काम कर रहा है, यहाँ विचार है:

public class MyAdapter extends XXXAdapter implements SectionIndexer { 
    ... 
    public void updateDataAndIndex(List data, Map index) { 
     // update sections 
     // update date set 
     notifyDataSetInvalidated(); 
    } 
} 

अद्यतन अपने डेटा सेट और सूचकांक (भागों) किसी भी तरह, और फिर notifyDataSetInvalidated, सूचकांक ताज़ा होगी।

संबंधित मुद्दे