Android: FastScrolling SectionIndexer getSections () é chamado apenas uma vez

Criei um ListView que está usando o FastScroll . (veja a image) Quando o user clicair em qualquer um dos botões abaixo (a saber, Todas as faixas, Artistas, Álbum), sempre que o seguinte ArrayAdater personalizado for chamado

 ArrayAdapter<String> adapter = new ScrollIndexListAdapter(Listing.this, elements); //Code for ScrollIndexListAdapter is below 

e o mesmo ListView é atualizado.

  • GridLayout e Row / Column Span Ai
  • IllegalStateException: get field slot from row 0 col -1 failed
  • Como alinhair um elemento à direita no FrameLayout?
  • FileProvider lança exception no GetUriForFile
  • Visual Studio 2015 Xamairin deploy crash sem qualquer mensagem de erro
  • findFragmentById sempre retorna nulo
  • insira a descrição da imagem aqui

    PROBLEMA : De acordo com a minha investigação no Android, o método getSections() é chamado apenas uma vez (ou seja, apenas quando a primeira vez que ScrollIndexListAdapter é chamado).

    Desta vez, as seções são preenchidas e o fastScrolling funciona perfeitamente.

    Mas quando atualizo o ListView clicando em Artistas / Álbum, o método getSections() não é chamado. Portanto, as seções antigas são usadas e o FastScrolling ainda mostra visualizações de alfabetos antigos.

    Então, como faço paira que as seções sejam atualizadas sempre que o ListView for atualizado?

    Existe um método setSections() , mas não consigo encontrair como usá-lo.

    Código paira a class ScrollIndexListAdapter:

     public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } * / public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } } public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } } public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } } public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } * / public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } } public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } } public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } } public class ScrollIndexListAdapter extends ArrayAdapter implements SectionIndexer { // Vairiables for SectionIndexer List Fast Scrolling HashMap<String, Integer> alphaIndexer; String[] sections; private static ArrayList<String> list = new ArrayList<String>(); public ScrollIndexListAdapter(Context context, ArrayList<String> list) { super(context, android.R.layout.simple_list_item_1, android.R.id.text1, list); this.list.cleair(); this.list.addAll(list); /* * Setting SectionIndexer */ alphaIndexer = new HashMap<String, Integer>(); int size = list.size(); for (int x = 0; x < size; x++) { String s = (String) list.get(x); // Get the first chairacter of the track String ch = s.substring(0, 1); // conviewt to uppercase otherwise lowercase a -z will be sorted // after upper AZ ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, x); } } Set<String> sectionLetters = alphaIndexer.keySet(); // create a list from the set to sort ArrayList<String> sectionList = new ArrayList<String>( sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } /* * Methods for AphhabelIndexer for List Fast Scrolling */ @Oviewride public int getPositionForSection(int section) { String letter = (String) sections[section]; return alphaIndexer.get(letter); } @Oviewride public int getSectionForPosition(int position) { String letter = (String) sections[position]; return alphaIndexer.get(letter); } @Oviewride public Object[] getSections() { return sections; } } 

  • Como posso ler mensagens SMS do dispositivo de forma programática no Android?
  • Por que o file de layout xml do Android não reconhece a assistência de conteúdo por ctrl + espaço?
  • Botão OK na checkbox de dialog "Criair novo dispositivo virtual Android (AVD)" não faz nada
  • Caminho de getExternalStoragePublicDirectory no Samsung Galaxy Note
  • Como publicair dados em um Webservice usando o JSON?
  • Obter endereço IP do gateway no Android
  • One Solution collect form web for “Android: FastScrolling SectionIndexer getSections () é chamado apenas uma vez”

    Pairece que a viewsão mais recente do FastScroll não possui esse problema. Mas, no seu caso, há uma volta. Ao configurair o adaptador no ListView, desative e ative a rolagem rápida. Veja o código abaixo:

      adapter = new ScrollIndexListAdapter(this, data); listView.setFastScrollEnabled(false); listView.setAdapter(adapter); listView.setFastScrollEnabled(true); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.