I am following a great coding example over here: This SO question. It is regarding implementing a SectionIndexer interface to an array adapter.
However, how would you do the same thing if your ArrayAdapter is passing an ArrayList< MyObject > not an ArrayList< String >?
For example, this is where my code is different then his code. He has:
class AlphabeticalAdapter extends ArrayAdapter<String> implements SectionIndexer {
private HashMap<String, Integer> alphaIndexer;
private String[] sections;
public AlphabeticalAdapter(Context c, int resource, List<String> data) {
alphaIndexer = new HashMap<String, Integer>();
for (int i = 0; i < data.size(); i++) {
String s = data.get(i).substring(0, 1).toUpperCase();
alphaIndexer.put(s, i);
}
// other stuff
}
I am having problems adapting that for loop to my situation. I can't measure the size like he does. Where he has the above, my adapter begins with.
public class CustomAdapter extends ArrayAdapter<Items> implements
SectionIndexer {
public ItemAdapter(Context context, Items[] objects) {
Where he is passing one ArrayList, I have to pass in three, but to make that happen, had to wrap in a custom object class. One of the ArrayLists that I want to sort is one of three fields in the class called "name". It is a string obviously.
I want to scroll through that alphabetically with SectionIndex based on that name field. How do I change the example code from the other question to work in this scenario?
Where he has "data.size()", I need something like "name.size()" - I think?