के पक्ष में वर्णमाला अक्षरों को कैसे दिखाया जाए I ListView को पक्ष में वर्णमाला अक्षरों (संपर्क सूची की तरह) बनाने के लिए कई ट्यूटोरियल देख चुके हैं, लेकिन वे सभी एक सूची एक्टिविटी क्लास का उपयोग करने लगते हैं और/या डेटाबेस से डेटा जबकि मैं सिर्फ एक सूची दृश्य (कोई विशेष गतिविधि) और डेटा के एक ArrayList का उपयोग कर रहा हूँ। क्या किसी को पता है कि मैं अपनी सूची सूची के लिए संपर्क सूची में उस वर्णमाला-स्क्रॉल सुविधा को कैसे कार्यान्वित कर सकता हूं?एंड्रॉइड लिस्ट व्यू
संपादित फिर
मैं this tutorial, जो मैंने सोचा था कि अंत में यह काम होगा पीछा किया, लेकिन मैं अभी भी एक करीबी के लिए मजबूर हो रही है।
class AlphabeticalAdapter extends ArrayAdapter<String> implements SectionIndexer
{
private HashMap<String, Integer> alphaIndexer;
private String[] sections;
public AlphabeticalAdapter(Context c, int resource, List<String> data)
{
super(c, resource, data);
for (int i = 0; i < data.size(); i++)
{
String s = data.get(i).substring(0, 1).toUpperCase();
alphaIndexer.put(s, i);
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
sectionList.toArray(sections);
}
public int getPositionForSection(int section)
{
return alphaIndexer.get(sections[section]);
}
public int getSectionForPosition(int position)
{
return 1;
}
public Object[] getSections()
{
return sections;
}
}
LogCat में, यह java.lang.RuntimeException: Unable to resume activity {(package of another app I made) android.app.SuperNotCalledExcpetion
कहते हैं। मैंने सोचा कि वास्तव में अजीब था क्योंकि मैं उस दूसरे ऐप का संदर्भ नहीं देता जिस पर मैं काम कर रहा हूं। मैंने उस ऐप को अनइंस्टॉल करने का प्रयास किया, फिर भी मजबूर बंद हो गया, लेकिन मैं देख सकता था कि लॉगकैट ने क्या कहा क्योंकि यह अपडेट नहीं हुआ था।
अंतिम संपादित
यहाँ काम कर कोड है। इसे 9 महीने के अतिदेय जैसे कुछ पोस्ट करने के लिए खेद है।
class AlphabeticalAdapter extends ArrayAdapter<String> implements SectionIndexer
{
private HashMap<String, Integer> alphaIndexer;
private String[] sections;
public AlphabeticalAdapter(Context c, int resource, List<String> data)
{
super(c, resource, data);
alphaIndexer = new HashMap<String, Integer>();
for (int i = 0; i < data.size(); i++)
{
String s = data.get(i).substring(0, 1).toUpperCase();
if (!alphaIndexer.containsKey(s))
alphaIndexer.put(s, i);
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
for (int i = 0; i < sectionList.size(); i++)
sections[i] = sectionList.get(i);
}
public int getPositionForSection(int section)
{
return alphaIndexer.get(sections[section]);
}
public int getSectionForPosition(int position)
{
for (int i = sections.length - 1; i >= 0; i--) {
if (position >= alphaIndexer.get(sections[ i ])) {
return i;
}
}
return 0;
}
public Object[] getSections()
{
return sections;
}
}
संपादित करें: getSectionForPosition महत्वपूर्ण यदि आप अपने स्क्रोलर सही जगह में दिखाई देता है जबकि आप स्क्रॉल कर रहे हैं चाहते हैं। केवल 1 (या 0) लौटने से पता चलता है कि आप केवल पहले (या दूसरे) खंड में स्क्रॉल कर रहे हैं जिसके परिणामस्वरूप स्क्रोलर की गलत स्थिति होगी (ज्यादातर स्क्रीन से बाहर हो जाती है)। जोड़ा गया कोड उचित खंड देता है ताकि स्क्रॉलर यह जान सके कि यह वास्तव में कहां है।
क्या कोई कारण है कि आप ListActivity का उपयोग नहीं करना चाहते हैं? क्या आप उन ट्यूटोरियल्स से लिंक कर सकते हैं जिनके बारे में आप बात करते हैं? –
सबस्ट्रिंग (0, 0)? –
शब्द –