Add String to adapter
- by Waggoner_Keith
I have an adapter and i want to add a string to it but when i run this code it only add the last string in the songstoadd variable ... That is a custom adapter which adds dividers in where neccessary but in the Array Adapter i want to a all of the strings that have the same first letter in their name ....
SeparatedListAdapter adapter = new SeparatedListAdapter(this);
ArrayList<String> songstoadd = new ArrayList<String>();
Collections.sort(songtitle);
int m = 0;
while( m <songtitle.size()-1){
if(songtitle.get(m).substring(0, 1) == songtitle.get(m+1).substring(0, 1)){
m++;
}else{
songstoadd.clear();
songstoadd.add(songtitle.get(m));
adapter.addSection(songtitle.get(m).substring(0, 1), new ArrayAdapter<String>(getApplicationContext(),R.layout.song, songstoadd));
m++;
}
}
setListAdapter(adapter);
}