android - Dynamically changing TextView color for Three different group in ListView [Solved] -


this current output

i trying develop listview index. in case 3 level of list, chapter, subchapter , child.. implement 3 level.

i want change 3 different color 3 list.

tried:

  1. i tried 3 level expentable listview cant able achieve.

  2. so tried listview more dynamically single array..

now want change list color in listview getview method

this getview() adding subchapter list:

            (int = listsubchapt.size() - 1; >= 0; i--) {                  mainarray.add(pos + 1, listsubchapt.get(i));                 mainarrayid.add(pos + 1, listsubchaptid.get(i));                  //system.out.println("mainarraywithsub==++ " + mainarray);                 arrayadapter<string> adapter = (new arrayadapter<string>(                         indexchapter.this, r.layout.singlerow,                         r.id.textview1, mainarray){@override                         public view getview(int position,                                 view convertview, viewgroup parent) {                              layoutinflater minflater = (layoutinflater)getsystemservice(                                     context.layout_inflater_service);                          convertview = minflater.inflate(r.layout.singlerow, null);                           for(int i=0;i<mainarray.size();i++){                              string sample=mainarray.get(i);                             string[] items = sample.split(":");                              if (items.length == 1) {                                 textview txt = ((textview) convertview.findviewbyid(r.id.textview1));                                 txt.setbackgroundcolor(color.cyan);                              }else if(items.length == 2){                                 textview txt = ((textview) convertview.findviewbyid(r.id.textview1));                                 txt.setbackgroundcolor(color.blue);                             }else if(items.length == 3){                                 textview txt = ((textview) convertview.findviewbyid(r.id.textview1));                                 txt.setbackgroundcolor(color.gray);                             }else{                                 textview txt = ((textview) convertview.findviewbyid(r.id.textview1));                                 txt.setbackgroundcolor(color.cyan);                             }                          }                             return super.getview(position, convertview, parent);                         }});                   clientdetailslist.setadapter(adapter);                 clientdetailslist.setselection(pos-1);                 adapter.notifydatasetchanged();              }  

edit :

its moving length=1 block , changing values cyan color.

return convertview instead of super.getview(...). here examples: https://github.com/codepath/android_guides/wiki/using-an-arrayadapter-with-listview


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -