changing the button background color based upon the button text value in android -


i've created android application creates 50 button dynamically,which works perfectly, problem when press 1 button defined statically results in changing button (text named 5) background color yellow.

can please tell me solution code given below
android platform 2.3.3

import android.app.activity; import android.os.bundle; import android.view.viewgroup.layoutparams; import android.widget.button; import android.widget.linearlayout;  public class mymain extends activity { button change;     @override     public void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         change= (button) findviewbyid(r.id.change);            setcontentview(r.layout.mymain);         createcalender();         change.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {               // write here in order change color of button titled 5 yellow background color          }     });     }    public void createcalender()    {       linearlayout layoutvertical = (linearlayout) findviewbyid(r.id.livlayout);     linearlayout.layoutparams param = new linearlayout.layoutparams(             layoutparams.wrap_content,             layoutparams.wrap_content, 1.0f);       param.setmargins(10, 10, 10, 10);       linearlayout rowlayout=null;     button[][] buttons = new button[10][5];      int count=51;     int tab=1;     (int = 0; i<10; i++)      {         if(count%5==1)         {             rowlayout = new linearlayout(this);             rowlayout.setbackgroundcolor(color.black);             rowlayout.setweightsum(5);             layoutvertical.addview(rowlayout,param);             count=count-5;         }         for(int j=0;j<5;j++)         {             buttons[i][j]=new button(this);             buttons[i][j].settext(""+tab);             buttons[i][j].setheight(55);             buttons[i][j].setwidth(80);             buttons[i][j].settextcolor(color.black);             buttons[i][j].setbackgroundcolor(color.green);              tab++;              rowlayout.addview(buttons[i][j],param);          }     } }  } 

try like:

if("5".equals(v.gettext())){     v.setbackgroundcolor(color.yellow); } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -