java - Android - Change text of button in a selected row -


i've tried nothing have worked. have listview this:

   [ checkbox ] | [textview] | [button] 

what i'm trying change text of [button] in row witch [ checkbox ] checked. here problematic block of code:

public view getview(int position, view convertview, viewgroup parent){         final viewholder vh;         final view conv;          if(convertview == null){             layoutinflater vi=(layoutinflater)pcontext.getsystemservice(context.layout_inflater_service);             convertview=vi.inflate(r.layout.rest_dishes_item, null);             conv=convertview;             final button b[];             b=new button[itens.size()];             vh=new viewholder();             vh.txt=(textview)convertview.findviewbyid(r.id.dish_name);             vh.checkbox=(checkbox) convertview.findviewbyid(r.id.dish_item);             vh.qnt=(button) convertview.findviewbyid(r.id.qnt);              vh.quantidade=new quantidade[itens.size()];             for(int i=0;i<itens.size();i++){                 b[i]=(button)conv.findviewbyid(r.id.qnt);                 vh.quantidade[i].quantidade=1;                 vh.quantidade[i].order=i;             }             vh.qnt.setonclicklistener(new onclicklistener(){                  @override                 public void onclick(view v) {                     // todo auto-generated method stub                     for(int i=0;i<itens.size();i++){                         titem item=itens.get(i);                         if(item.ischeck()){                             vh.quantidade[i].quantidade++;                             //log.d("teste",i+""+vh.quantidade[i].quantidade);                             b[i].settext(string.valueof(vh.quantidade[i].quantidade));                         }                         else if(!item.ischeck()){                             log.d("teste",i+"1");                             b[i].settext(string.valueof(1));                         }                     }                  }              });                     //(button) convertview.findviewbyid(r.id.qnt);                convertview.settag(vh);               vh.checkbox.setonclicklistener(new view.onclicklistener() {                  @override                 public void onclick(view arg0) {                     // todo auto-generated method stub                     checkbox box=(checkbox) arg0;                     titem item=(titem)box.gettag();                      item.setcheck(box.ischecked());                 }             });         }else{             vh=(viewholder)convertview.gettag();         }          titem item=itemlist.get(position);            vh.txt.settext(item.getname());         vh.checkbox.settext(item.getname());         vh.checkbox.setchecked(item.ischeck());         vh.checkbox.settag(item);          //log.d("teste","chegou aqui");          return convertview;     } 

with code text of buttons doesn't change @ all, no matter button click text still "1".

without line:

b[i].settext(string.valueof(1)); 

the button of checked row has text changed want. when click button of non checked row, clicked button has text changed.

maybe i'm doing stupid or missing in algorithm, @ moment i'm stuck.

please help. thanks.

sounds confused, getview() executed once per visible item. code:

        vh.qnt=(button) convertview.findviewbyid(r.id.qnt);          vh.quantidade=new quantidade[itens.size()];         for(int i=0;i<itens.size();i++){             b[i]=(button)conv.findviewbyid(r.id.qnt);             vh.quantidade[i].quantidade=1;             vh.quantidade[i].order=i;         } 

vh.qnt , instances of b[i] reference exact same button (r.id.qnt) in row being rendered.

you need update text of button after if/else, when update rest of vh views.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -