title: Dynamically created checkboxes with edittext and spinner children in Android
body: <p>What I am trying to do is on selection of any item, from spinner, dynamically create a checkbox and when the checkbox is checked then I dynamically create edittext with a spinner. I got the layout but I am not sure what to do with edittext and selected spinner item (that are visible) and append it to a string. </p>
  
  <blockquote>
    <p>for eg: checkeditem:childspinner;checkitem:childspinner etc</p>
  </blockquote>
  
  <p>Below is what I have tried but I am not able to get the text, spinner item and put it in the format. Any help would be appreciated.</p>
  
  <pre><code>checkBoxes = new CheckBox(Activity1.this);
  checkBoxes.setText(materials[i]);
  
  String matId = materialListIdMap.get(materials[i]);
  checkBoxes.setId(Integer.parseInt(matId));
  materialsUsedLayout.addView(checkBoxes);
  
  EditText edittext=new EditText(Activity1.this);
  edittext.setHint("Count");
  allEds.add(edittext);
  edittext.setVisibility(View.GONE);
  
  Spinner uomSpinner = new Spinner(Activity1.this);
  uomSpinner.setAdapter(unitofMeasurementAdapter);
  uomSpinner.setVisibility(View.GONE);
  
  materialsUsedLayout.addView(edittext);
  materialsUsedLayout.addView(uomSpinner);
  
  
  checkBoxes.setOnClickListener(getOnClickDoSomething(checkBoxes, edittext, uomSpinner));
  
  View.OnClickListener getOnClickDoSomething(final CheckBox button, final EditText      edittext, final Spinner uomSpinner)
  {
      return new View.OnClickListener() 
      { 
          public void onClick(View v) { 
              if (button.isChecked()) {
  
                  edittext.setVisibility(View.VISIBLE);
                  uomSpinner.setVisibility(View.VISIBLE);
  
                  uomSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id)
                      {           
                          Object obj = parent.getItemAtPosition(pos);   
                          String newtext=edittext.getText().toString();
                          uomid=unitofMeasurementIdMap.get(obj);
  
                          System.out.println("*************id**"+newtext+"****" + button.getId()+"\\   \\"+uomid); 
  
                          StringBuffer edtBuffer = new StringBuffer();
                          edtBuffer.append(button.getId()+":"+uomid+";");
                      }
                      public void onNothingSelected(AdapterView&lt;?&gt; parent) { }    
  
                  });
  
                  System.out.println("*************id******" + button.getId()+"\\   \\"+uomid); 
                  System.out.println("and text***" + button.getText().toString()); 
  
                  //System.out.println("buffer: "+edtBuffer);
              }
              else
              {
                  edittext.setVisibility(View.GONE);
                  uomSpinner.setVisibility(View.GONE);
                  System.out.println("no checking");
              }
          } 
      };
  </code></pre>