java - Show both radio button and checkbox based on database value -


i m working on radio button , checkbox button. value 0 radio , 1 checkbox. based on these values, display on screen. there might both radio , checkboxes.

right now, value im getting 0 , 1 database, setting either radio button or checkbox attributes. should display checkbox value 1 , radio button value of 0.

here code:

                           if(multiselect != null)                                 {                                     radiobutton radiobutton = new radiobutton(mmain);                                     radiobutton.settext(name_price);                                     radiobutton.setid(i + 6);                                     radiobutton.settextsize(12);                                     radiobutton.settag(attributes.get(num));                                     radiobutton.setgravity(gravity.start | gravity.center_vertical);                                     if (build.version.sdk_int >= build.version_codes.jelly_bean_mr1)                                     {                                         radiobutton.settextalignment(view.text_alignment_view_start);                                     }                                     settextfont(radiobutton, "museo_slab.otf");                                      linearlayout.layoutparams lp = new linearlayout.layoutparams(                                             linearlayout.layoutparams.match_parent,                                             linearlayout.layoutparams.wrap_content,                                             1f);                                     lp.setmargins(10, 10, 0, 10); // llp.setmargins(left, top, right, bottom);                                      radiobutton.setlayoutparams(lp);                                      attr_layout[j].addview(radiobutton);                                     num++;                                      radiobutton.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener()                                     {                                         @override                                         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked)                                         {                                             try                                             {                                                 itemattributes itemattributes = (itemattributes) buttonview.gettag();                                                  if (ischecked)                                                 {                                                      float total_price = current_price + attr_price;                                                      item.setitemprice(total_price + "");                                                      item_price_text.settext(pricestr);                                                      selectedattributes.add(itemattributes);                                                 }                                                 // if attributes not checked                                              } catch (exception ex)                                             {                                                 gslogger.e(ex);                                             }                                         }                                     });                                 }                                  else // if multiselect 1                                 {                                     checkbox checkbox = new checkbox(mmain);                                     checkbox.settext(name_price);                                     checkbox.setid(i + 6);                                     checkbox.settextsize(12);                                     checkbox.settag(attributes.get(num));                                     checkbox.setgravity(gravity.start | gravity.center_vertical);                                     if (build.version.sdk_int >= build.version_codes.jelly_bean_mr1)                                     {                                         checkbox.settextalignment(view.text_alignment_view_start);                                     }                                     settextfont(checkbox, "museo_slab.otf");                                      linearlayout.layoutparams lp = new linearlayout.layoutparams(                                             linearlayout.layoutparams.match_parent,                                             linearlayout.layoutparams.wrap_content,                                             1f);                                     lp.setmargins(10, 10, 0, 10); // llp.setmargins(left, top, right, bottom);                                      checkbox.setlayoutparams(lp);                                      attr_layout[j].addview(checkbox);                                     num++;                                      // reads value depending on attribute user selects                                     checkbox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener()                                     {                                         @override                                         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked)                                         {                                             try                                             {                                                 itemattributes itemattributes = (itemattributes) buttonview.gettag();                                                  if (ischecked)                                                 {                                                      float total_price = current_price + attr_price;                                                      item.setitemprice(total_price + "");                                                      item_price_text.settext(pricestr);                                                     selectedattributes.add(itemattributes);                                                 }                                              } catch (exception ex)                                             {                                                 gslogger.e(ex);                                             }                                         }                                     });                                 }                             }                         }                     } 

based on items group defined 0 or 1, should display on screen. if group has both options, screen should display both radio 0 value , checkbox 1 value.

your if condition allows either of these added. should check if value 0 add radio button , if value 1 should add checkbox. have implemented if else block instead of 2 if blocks.

   if(value == 0)     {         radiobutton radiobutton = new radiobutton(mmain);         radiobutton.settext(name_price);         radiobutton.setid(i + 6);         radiobutton.settextsize(12);         radiobutton.settag(attributes.get(num));         radiobutton.setgravity(gravity.start | gravity.center_vertical);         if (build.version.sdk_int >= build.version_codes.jelly_bean_mr1)         {             radiobutton.settextalignment(view.text_alignment_view_start);         }         settextfont(radiobutton, "museo_slab.otf");          linearlayout.layoutparams lp = new linearlayout.layoutparams(                 linearlayout.layoutparams.match_parent,                 linearlayout.layoutparams.wrap_content,                 1f);         lp.setmargins(10, 10, 0, 10); // llp.setmargins(left, top, right, bottom);          radiobutton.setlayoutparams(lp);          attr_layout[j].addview(radiobutton);         num++;          radiobutton.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener()         {             @override             public void oncheckedchanged(compoundbutton buttonview, boolean ischecked)             {                 try                 {                     itemattributes itemattributes = (itemattributes) buttonview.gettag();                      if (ischecked)                     {                          float total_price = current_price + attr_price;                          item.setitemprice(total_price + "");                          item_price_text.settext(pricestr);                          selectedattributes.add(itemattributes);                     }                     // if attributes not checked                  } catch (exception ex)                 {                     gslogger.e(ex);                 }             }         });     }      if(value==1)     {         checkbox checkbox = new checkbox(mmain);         checkbox.settext(name_price);         checkbox.setid(i + 6);         checkbox.settextsize(12);         checkbox.settag(attributes.get(num));         checkbox.setgravity(gravity.start | gravity.center_vertical);         if (build.version.sdk_int >= build.version_codes.jelly_bean_mr1)         {             checkbox.settextalignment(view.text_alignment_view_start);         }         settextfont(checkbox, "museo_slab.otf");          linearlayout.layoutparams lp = new linearlayout.layoutparams(                 linearlayout.layoutparams.match_parent,                 linearlayout.layoutparams.wrap_content,                 1f);         lp.setmargins(10, 10, 0, 10); // llp.setmargins(left, top, right, bottom);          checkbox.setlayoutparams(lp);          attr_layout[j].addview(checkbox);         num++;          // reads value depending on attribute user selects         checkbox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener()         {             @override             public void oncheckedchanged(compoundbutton buttonview, boolean ischecked)             {                 try                 {                     itemattributes itemattributes = (itemattributes) buttonview.gettag();                      if (ischecked)                     {                          float total_price = current_price + attr_price;                          item.setitemprice(total_price + "");                          item_price_text.settext(pricestr);                         selectedattributes.add(itemattributes);                     }                  } catch (exception ex)                 {                     gslogger.e(ex);                 }             }         });     } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -