Add String to adapter
Posted
by
Waggoner_Keith
on Stack Overflow
See other posts from Stack Overflow
or by Waggoner_Keith
Published on 2011-11-22T09:25:43Z
Indexed on
2011/11/22
17:51 UTC
Read the original article
Hit count: 248
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);
}
© Stack Overflow or respective owner