java - Change color of one textview on listview without change others -


i need change color of listview backgroundcolor property. can it, change color, changes rows same color. mean, need 1 row red color, other green color... put code below help:

 arrayadapter<string> adapter = new arrayadapter<string>(getapplicationcontext(), android.r.layout.simple_list_item_1, configurelist(idruta, rocodromo, dificultad))            {               @override               public view getview(int position, view convertview, viewgroup parent)                {                    view view = super.getview(position, convertview, parent);                   textview text = (textview) view.findviewbyid(android.r.id.text1);                   for(int = 0; < colores.size(); i++)                  {                      if(colores.get(i).equals("0"))                      {                          text.setbackgroundcolor(color.green);                      }                      else if(colores.get(i).equals("1"))                      {                          text.setbackgroundcolor(color.red);                      }                      else if(colores.get(i).equals("2"))                      {                          text.setbackgroundcolor(color.yellow);                      }                      else                      {                          text.setbackgroundcolor(color.white);                      }                  }                   return view;               }           }; 

at first time, have "colores.get(i) = 1", changes color red, have "colores.get(i) = 2", changes color yellow. need change second row yellow, not first one, first 1 has red.

in "colores" have color list need change, order row, example, when "i=0", change row 0 color, when "i=1" want change row 1, not rows.

can helps me? thanks!

i think should take in account "position" parameter given function getview. assume have first row: green, next red, next yellow, , rest white. so:

arrayadapter<string> adapter = new arrayadapter<string>(getapplicationcontext(), android.r.layout.simple_list_item_1, configurelist(idruta, rocodromo, dificultad))        {           @override           public view getview(int position, view convertview, viewgroup parent)            {                view view = super.getview(position, convertview, parent);               textview text = (textview) view.findviewbyid(android.r.id.text1);                    if(colores.get(position).equals("0"))                  {                      text.setbackgroundcolor(color.green);                  }                  else if(colores.get(position).equals("1"))                  {                      text.setbackgroundcolor(color.red);                  }                  else if(colores.get(position).equals("2"))                  {                      text.setbackgroundcolor(color.yellow);                  }                  else                  {                      text.setbackgroundcolor(color.white);                  }                return view;           }       }; 

in approach each row (poistion index) tested color.

iteration through colors array not necessary here, because "position" index should equal index of color colors array.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -