android - ArrayAdapter.getView returns only the last item being fetch -


here getview code. returns last item being fetched. how can resolve problem. new holderview. *updated codes

public static final char[] alpha = {'a', 'b'....}; int[] icons = {r.drawable.a, r.drawable.b....}; public customlist(context context, character[] split) {     super(context, r.layout.activity_list, split);     inflater = layoutinflater.from(context);     this.alphasplit = split; } static class holder {     imageview imageview; } @override public view getview(int position, view convertview, viewgroup parent) {     holder holder;     if (convertview == null) {         convertview = inflater.inflate(r.layout.activity_list, parent, false);         holder = new holder();         holder.imageview = (imageview)convertview.findviewbyid(r.id.img);         convertview.settag(holder);     } else {         holder = (holder)convertview.gettag();     }      setimage:     (int loop = 0; loop < alphasplit.length; loop++) {         (int j = 0; j < alpha.length; j++) {             if (alphasplit[loop] == alpha[j]) {                 holder.imageview.setimageresource(icons[j]);                 break setimage;             }         }     }     return convertview; } 

i wanted corresponding image of each letter. why having nested loop because there, position of icons. outer loop text user inputs , parse character(since make errors if going use char). , inner loop char of alpha = {'a', 'b'.. until 'z' , '0' '9'}

in method getview, loop should break when matched this:

for (int loop = 0; loop < alphasplit.length; loop++) {     (int j = 0; j < alpha.length; j++) {         if (alphasplit[loop] == alpha[j]) {             holder.imageview.setimageresource(icons[j]);             break; //attention pls!!!         }     } } 

btw, need not invoke notifydatasetchanged in getview. fyi

ps: maybe need break 2 loops this:

outer: (int loop = 0; loop < alphasplit.length; loop++) {     (int j = 0; j < alpha.length; j++) {         if (alphasplit[loop] == alpha[j]) {             holder.imageview.setimageresource(icons[j]);             break outer; //attention pls!!!         }     } } 

update:

change code :

 setimage: (int loop = 0; loop < alphasplit.length; loop++) {     (int j = 0; j < alpha.length; j++) {         if (alphasplit[loop] == alpha[j]) {             holder.imageview.setimageresource(icons[j]);             break setimage;         }     } } 

like this:

for (int j = 0; j < alpha.length; j++) {    if (alphasplit[position] == alpha[j]) {         holder.imageview.setimageresource(icons[j]);         break;     } } 

and override getcount method:

@override public int getcount() {     return this.alphaslipt.length; } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -